aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-26 19:18:06 +0100
committerFederico Angelilli <code@fedang.net>2023-11-26 19:18:06 +0100
commitf9ec9bb88ae2b1423d30da21c76a7e131cb383cc (patch)
treea915818953d4e5343e39cbbadf06621864bdb525 /src
parent5a8c1c34a0a739a01853406b737cc7497884ed7a (diff)
Start working on button hovering
Diffstat (limited to 'src')
-rw-r--r--src/connect.c26
-rw-r--r--src/window.c1
2 files changed, 16 insertions, 11 deletions
diff --git a/src/connect.c b/src/connect.c
index b3e4e92..12038a4 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -77,25 +77,21 @@ static inline bool in_capsule(int px, int py, int x, int y, int w, int h)
|| in_rect(px, py, x + radius, y, w - 2 * radius, h);
}
-static void button_action(State *state, xcb_button_release_event_t *button)
+static void button_action(State *state, const char *event, int x, int y)
{
- log_debug("Button release event [x=%d, y=%d]", button->event_x, button->event_y);
+ log_debug("Checking %s event [x=%d, y=%d]", event, x, y);
for (GList *it = state->draw->layouts; it != NULL; it = it->next) {
Layout *layout = it->data;
// Skip
- if (layout->x + layout->width < button->event_x) continue;
- if (layout->x > button->event_x) break;
-
- bool check = in_capsule(button->event_x, button->event_y,
- layout->x, layout->y,
- layout->width, layout->height);
+ if (layout->x + layout->width < x) continue;
+ if (layout->x > x) break;
log_debug("Button layout [x=%d, y=%d, w=%d, h=%d]",
layout->x, layout->y, layout->width, layout->height);
- if (check) {
+ if (in_capsule(x, y, layout->x, layout->y, layout->width, layout->height)) {
log_debug("Triggering action for button");
if (layout->btn->action != NULL) {
layout->btn->action(layout->btn);
@@ -104,7 +100,7 @@ static void button_action(State *state, xcb_button_release_event_t *button)
}
}
- log_debug("Ignoring button release");
+ log_debug("Ignoring %s", event);
}
typedef struct {
@@ -181,7 +177,7 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
case XCB_BUTTON_INDEX_2: // left click
case XCB_BUTTON_INDEX_1: // right click
case XCB_BUTTON_INDEX_3: // middle click
- button_action(xsource->con->state, button);
+ button_action(xsource->con->state, "button release", button->event_x, button->event_y);
break;
default:
@@ -191,6 +187,14 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
break;
}
+ // TODO: Implement correctly hovering
+ case XCB_MOTION_NOTIFY: {
+ xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xsource->event;
+ log_debug("Processing event 'MotionNotify' [type=%d]", XCB_MOTION_NOTIFY);
+ button_action(xsource->con->state, "motion notify", motion->event_x, motion->event_y);
+ break;
+ }
+
case XCB_PROPERTY_NOTIFY: {
xcb_property_notify_event_t *property = (xcb_property_notify_event_t *)xsource->event;
log_debug("Processing event 'PropertyNotify' [type=%d]", XCB_PROPERTY_NOTIFY);
diff --git a/src/window.c b/src/window.c
index cadf891..360f0d5 100644
--- a/src/window.c
+++ b/src/window.c
@@ -117,6 +117,7 @@ Window *window_create(Connection *con)
uint32_t event_mask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY
| XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_FOCUS_CHANGE
| XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS;
+ //| XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT;
xcb_colormap_t colormap = xcb_generate_id(con->connection);
xcb_create_colormap(con->connection, XCB_COLORMAP_ALLOC_NONE, colormap, con->screen->root, con->visual_type->visual_id);