add grab/ungrab macros so dont need to pass in 10 arguments to ungrab stuff.

add a confine option to grab_pointer to confine the pointer to the screen, and use that for moveresize
This commit is contained in:
Dana Jansens 2007-05-13 23:30:52 +00:00
parent 627125a6c6
commit 9fcb2aa1d2
6 changed files with 32 additions and 21 deletions

View file

@ -42,7 +42,7 @@ inline void client_action_start(union ActionData *data)
{ {
if (config_focus_follow) if (config_focus_follow)
if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button) if (data->any.context != OB_FRAME_CONTEXT_CLIENT && !data->any.button)
grab_pointer(TRUE, FALSE, OB_CURSOR_NONE); grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
} }
inline void client_action_end(union ActionData *data) inline void client_action_end(union ActionData *data)
@ -50,7 +50,7 @@ inline void client_action_end(union ActionData *data)
if (config_focus_follow) if (config_focus_follow)
if (data->any.context != OB_FRAME_CONTEXT_CLIENT) { if (data->any.context != OB_FRAME_CONTEXT_CLIENT) {
if (!data->any.button) { if (!data->any.button) {
grab_pointer(FALSE, FALSE, OB_CURSOR_NONE); ungrab_pointer();
} else { } else {
ObClient *c; ObClient *c;

View file

@ -67,7 +67,7 @@ gboolean grab_on_pointer()
return pgrabs > 0; return pgrabs > 0;
} }
gboolean grab_keyboard(gboolean grab) gboolean grab_keyboard_full(gboolean grab)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
@ -92,7 +92,8 @@ gboolean grab_keyboard(gboolean grab)
return ret; return ret;
} }
gboolean grab_pointer(gboolean grab, gboolean owner_events, ObCursor cur) gboolean grab_pointer_full(gboolean grab, gboolean owner_events,
gboolean confine, ObCursor cur)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
@ -100,7 +101,9 @@ gboolean grab_pointer(gboolean grab, gboolean owner_events, ObCursor cur)
if (pgrabs++ == 0) { if (pgrabs++ == 0) {
ret = XGrabPointer(ob_display, screen_support_win, owner_events, ret = XGrabPointer(ob_display, screen_support_win, owner_events,
GRAB_PTR_MASK, GRAB_PTR_MASK,
GrabModeAsync, GrabModeAsync, None, GrabModeAsync, GrabModeAsync,
(confine ? RootWindow(ob_display, ob_screen) :
None),
ob_cursor(cur), event_curtime) == Success; ob_cursor(cur), event_curtime) == Success;
if (!ret) if (!ret)
--pgrabs; --pgrabs;
@ -158,8 +161,8 @@ void grab_shutdown(gboolean reconfig)
{ {
if (reconfig) return; if (reconfig) return;
while (grab_keyboard(FALSE)); while (ungrab_keyboard());
while (grab_pointer(FALSE, FALSE, OB_CURSOR_NONE)); while (ungrab_pointer());
while (grab_server(FALSE)); while (grab_server(FALSE));
} }

View file

@ -27,10 +27,17 @@
void grab_startup(gboolean reconfig); void grab_startup(gboolean reconfig);
void grab_shutdown(gboolean reconfig); void grab_shutdown(gboolean reconfig);
gboolean grab_keyboard(gboolean grab); gboolean grab_keyboard_full(gboolean grab);
gboolean grab_pointer(gboolean grab, gboolean owner_events, ObCursor cur); /*! @param confine If true the pointer is confined to the screen */
gboolean grab_pointer_full(gboolean grab, gboolean owner_events,
gboolean confine, ObCursor cur);
gint grab_server(gboolean grab); gint grab_server(gboolean grab);
#define grab_keyboard() grab_keyboard_full(TRUE)
#define ungrab_keyboard() grab_keyboard_full(FALSE)
#define grab_pointer(o,c,u) grab_pointer_full(TRUE, (o), (c), (u))
#define ungrab_pointer() grab_pointer_full(FALSE, FALSE, FALSE, OB_CURSOR_NONE)
gboolean grab_on_keyboard(); gboolean grab_on_keyboard();
gboolean grab_on_pointer(); gboolean grab_on_pointer();

View file

@ -197,7 +197,7 @@ static void keyboard_interactive_end(guint state, gboolean cancel, Time time,
/* ungrab first so they won't be NotifyWhileGrabbed */ /* ungrab first so they won't be NotifyWhileGrabbed */
if (ungrab) if (ungrab)
grab_keyboard(FALSE); ungrab_keyboard();
/* set this before running the actions so they know the keyboard is not /* set this before running the actions so they know the keyboard is not
grabbed */ grabbed */
@ -226,7 +226,7 @@ gboolean keyboard_interactive_grab(guint state, ObClient *client,
g_assert(action->data.any.interactive); g_assert(action->data.any.interactive);
if (!istate.active) { if (!istate.active) {
if (!grab_keyboard(TRUE)) if (!grab_keyboard())
return FALSE; return FALSE;
} else if (action->func != istate.action->func) { } else if (action->func != istate.action->func) {
keyboard_interactive_end(state, TRUE, action->data.any.time, FALSE); keyboard_interactive_end(state, TRUE, action->data.any.time, FALSE);

View file

@ -914,10 +914,10 @@ static gboolean menu_frame_show(ObMenuFrame *self)
/* grab the pointer in such a way as to pass through "owner events" /* grab the pointer in such a way as to pass through "owner events"
so that we can get enter/leave notifies in the menu. */ so that we can get enter/leave notifies in the menu. */
if (!grab_pointer(TRUE, TRUE, OB_CURSOR_POINTER)) if (!grab_pointer(TRUE, FALSE, OB_CURSOR_POINTER))
return FALSE; return FALSE;
if (!grab_keyboard(TRUE)) { if (!grab_keyboard()) {
grab_pointer(FALSE, TRUE, OB_CURSOR_POINTER); ungrab_pointer();
return FALSE; return FALSE;
} }
} }
@ -1035,8 +1035,8 @@ void menu_frame_hide(ObMenuFrame *self)
if (menu_frame_visible == NULL) { if (menu_frame_visible == NULL) {
/* last menu shown */ /* last menu shown */
grab_pointer(FALSE, TRUE, OB_CURSOR_NONE); ungrab_pointer();
grab_keyboard(FALSE); ungrab_keyboard();
} }
XUnmapWindow(ob_display, self->window); XUnmapWindow(ob_display, self->window);

View file

@ -187,10 +187,11 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr)
else else
g_assert_not_reached(); g_assert_not_reached();
if (!grab_pointer(TRUE, FALSE, cur)) /* keep the pointer bounded to the screen for move/resize */
if (!grab_pointer(FALSE, TRUE, cur))
return; return;
if (!grab_keyboard(TRUE)) { if (!grab_keyboard()) {
grab_pointer(FALSE, FALSE, OB_CURSOR_NONE); ungrab_pointer();
return; return;
} }
@ -275,8 +276,8 @@ void moveresize_end(gboolean cancel)
{ {
gint x, y; gint x, y;
grab_keyboard(FALSE); ungrab_keyboard();
grab_pointer(FALSE, FALSE, OB_CURSOR_NONE); ungrab_pointer();
popup_hide(popup); popup_hide(popup);