Skip to content

Commit

Permalink
Replace grab flag in PuglEventFocus with crossing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
drobilla committed Jul 5, 2020
1 parent eac255d commit 294c0f7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pugl/detail/mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ - (void) windowDidBecomeKey:(NSNotification*)notification
(void)notification;

PuglEvent ev = {{PUGL_FOCUS_IN, 0}};
ev.focus.grab = false;
ev.focus.mode = PUGL_CROSSING_NORMAL;
puglDispatchEvent(window->puglview, &ev);
}

Expand All @@ -787,7 +787,7 @@ - (void) windowDidResignKey:(NSNotification*)notification
(void)notification;

PuglEvent ev = {{PUGL_FOCUS_OUT, 0}};
ev.focus.grab = false;
ev.focus.mode = PUGL_CROSSING_NORMAL;
puglDispatchEvent(window->puglview, &ev);
}

Expand Down
7 changes: 6 additions & 1 deletion pugl/detail/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,12 @@ translateEvent(PuglView* view, XEvent xevent)
case FocusIn:
case FocusOut:
event.type = (xevent.type == FocusIn) ? PUGL_FOCUS_IN : PUGL_FOCUS_OUT;
event.focus.grab = (xevent.xfocus.mode != NotifyNormal);
event.focus.mode = PUGL_CROSSING_NORMAL;
if (xevent.xfocus.mode == NotifyGrab) {
event.focus.mode = PUGL_CROSSING_GRAB;
} else if (xevent.xfocus.mode == NotifyUngrab) {
event.focus.mode = PUGL_CROSSING_UNGRAB;
}
break;

default:
Expand Down
6 changes: 3 additions & 3 deletions pugl/pugl.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ typedef PuglEventAny PuglEventClose;
view with the keyboard focus will receive any key press or release events.
*/
typedef struct {
PuglEventType type; ///< #PUGL_FOCUS_IN or #PUGL_FOCUS_OUT
PuglEventFlags flags; ///< Bitwise OR of #PuglEventFlag values
bool grab; ///< True iff this is a grab/ungrab event
PuglEventType type; ///< #PUGL_FOCUS_IN or #PUGL_FOCUS_OUT
PuglEventFlags flags; ///< Bitwise OR of #PuglEventFlag values
PuglCrossingMode mode; ///< Reason for focus change
} PuglEventFocus;

/**
Expand Down
23 changes: 19 additions & 4 deletions test/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ printModifiers(const uint32_t mods)
(mods & PUGL_MOD_SUPER) ? " Super" : "");
}

static inline const char*
crossingModeString(const PuglCrossingMode mode)
{
switch (mode) {
case PUGL_CROSSING_NORMAL:
return "normal";
case PUGL_CROSSING_GRAB:
return "grab";
case PUGL_CROSSING_UNGRAB:
return "ungrab";
}

return "unknown";
}

static inline int
printEvent(const PuglEvent* event, const char* prefix, const bool verbose)
{
Expand Down Expand Up @@ -121,13 +136,13 @@ printEvent(const PuglEvent* event, const char* prefix, const bool verbose)
event->crossing.x,
event->crossing.y);
case PUGL_FOCUS_IN:
return PRINT("%sFocus in%s\n",
return PRINT("%sFocus in (%s)\n",
prefix,
event->focus.grab ? " (grab)" : "");
crossingModeString(event->crossing.mode));
case PUGL_FOCUS_OUT:
return PRINT("%sFocus out%s\n",
return PRINT("%sFocus out (%s)\n",
prefix,
event->focus.grab ? " (ungrab)" : "");
crossingModeString(event->crossing.mode));
case PUGL_CLIENT:
return PRINT("%sClient %" PRIXPTR " %" PRIXPTR "\n",
prefix,
Expand Down

0 comments on commit 294c0f7

Please sign in to comment.