Skip to content

Commit

Permalink
Merge pull request #95 from weihsinyeh/window_trigger
Browse files Browse the repository at this point in the history
Change the logic for window click detection
  • Loading branch information
jserv authored Feb 1, 2025
2 parents 2d855d2 + a9e6af3 commit 57a8f78
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 6 additions & 1 deletion include/twin.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,15 @@ void twin_window_configure(twin_window_t *window,
twin_coord_t width,
twin_coord_t height);

void twin_window_set_name(twin_window_t *window, const char *name);
/* Check if the coordinates are within the window's range. */
bool twin_window_valid_range(twin_window_t *window,
twin_coord_t x,
twin_coord_t y);

void twin_window_style_size(twin_window_style_t style, twin_rect_t *size);

void twin_window_set_name(twin_window_t *window, const char *name);

void twin_window_draw(twin_window_t *window);

void twin_window_damage(twin_window_t *window,
Expand Down
5 changes: 3 additions & 2 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ bool twin_screen_dispatch(twin_screen_t *screen, twin_event_t *event)

/* check who the mouse is over now */
for (ntarget = screen->top; ntarget; ntarget = ntarget->down)
if (!twin_pixmap_transparent(ntarget, event->u.pointer.screen_x,
event->u.pointer.screen_y))
if (twin_window_valid_range(ntarget->window,
event->u.pointer.screen_x,
event->u.pointer.screen_y))
break;

/* ah, somebody new ... send leave/enter events and set new target */
Expand Down
26 changes: 26 additions & 0 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ void twin_window_configure(twin_window_t *window,
twin_pixmap_enable_update(window->pixmap);
}

bool twin_window_valid_range(twin_window_t *window,
twin_coord_t x,
twin_coord_t y)
{
switch (window->style) {
case TwinWindowPlain:
default:
if (window->pixmap->x <= x &&
x < window->pixmap->x + window->pixmap->width &&
window->pixmap->y <= y &&
y < window->pixmap->y + window->pixmap->height)
return true;
return false;
case TwinWindowApplication:
if (window->pixmap->x <= x &&
x < window->pixmap->x + window->pixmap->width &&
window->pixmap->y <= y &&
y < window->pixmap->y + window->pixmap->height) {
if (y < window->pixmap->y + (window->client.top))
return !twin_pixmap_transparent(window->pixmap, x, y);
return true;
}
return false;
}
}

void twin_window_style_size(twin_window_style_t style, twin_rect_t *size)
{
switch (style) {
Expand Down

0 comments on commit 57a8f78

Please sign in to comment.