From 8401eee5f5ef8158bbbede4eb03b95c065dea5ea Mon Sep 17 00:00:00 2001 From: Nikos Ntarmos Date: Thu, 11 Oct 2007 07:46:28 +0300 Subject: [PATCH] Implementing a click-to-raise feature When in floating mode or in floating layout the only way to bring one window on top of another seems to be a focus switch through focusnext/focusprev. The following patch implements a click-to-raise feature. --- client.c | 22 +++++++++++++++++----- client.h | 1 + event.c | 15 +++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/client.c b/client.c index 4295f1be8..cd130603e 100644 --- a/client.c +++ b/client.c @@ -61,16 +61,28 @@ detachstack(Client * c) /** Grab or ungrab buttons when a client is focused * \param c client * \param focused True if client is focused + * \param raised True if the client is above other clients * \param modkey Mod key mask * \param numlockmask Numlock mask */ -static void -grabbuttons(Client * c, Bool focused, KeySym modkey, unsigned int numlockmask) +void +grabbuttons(Client * c, Bool focused, Bool raised, KeySym modkey, unsigned int numlockmask) { XUngrabButton(c->display, AnyButton, AnyModifier, c->win); if(focused) { + if (!raised) { + XGrabButton(c->display, Button1, NoSymbol, c->win, False, BUTTONMASK, + GrabModeAsync, GrabModeSync, None, None); + XGrabButton(c->display, Button1, LockMask, c->win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + XGrabButton(c->display, Button1, numlockmask, c->win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + XGrabButton(c->display, Button1, numlockmask | LockMask, + c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + } + XGrabButton(c->display, Button1, modkey, c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); XGrabButton(c->display, Button1, modkey | LockMask, c->win, False, @@ -317,7 +329,7 @@ focus(Display *disp, Client * c, Bool selscreen, awesome_config *awesomeconf) /* if a client was selected but it's not the current client, unfocus it */ if(sel && sel != c) { - grabbuttons(sel, False, awesomeconf->modkey, awesomeconf->numlockmask); + grabbuttons(sel, False, True, awesomeconf->modkey, awesomeconf->numlockmask); XSetWindowBorder(sel->display, sel->win, awesomeconf->colors_normal[ColBorder].pixel); setclienttrans(sel, awesomeconf->opacity_unfocused); } @@ -327,7 +339,7 @@ focus(Display *disp, Client * c, Bool selscreen, awesome_config *awesomeconf) { detachstack(c); attachstack(c); - grabbuttons(c, True, awesomeconf->modkey, awesomeconf->numlockmask); + grabbuttons(c, True, True, awesomeconf->modkey, awesomeconf->numlockmask); } if(!selscreen) return; @@ -434,7 +446,7 @@ manage(Display *disp, Window w, XWindowAttributes *wa, awesome_config *awesomeco XShapeSelectInput(disp, w, ShapeNotifyMask); set_shape(c); } - grabbuttons(c, False, awesomeconf->modkey, awesomeconf->numlockmask); + grabbuttons(c, False, True, awesomeconf->modkey, awesomeconf->numlockmask); updatetitle(c); move_client_to_screen(c, awesomeconf, False); if((rettrans = XGetTransientForHint(disp, w, &trans) == Success)) diff --git a/client.h b/client.h index d6ee3ff35..76948547f 100644 --- a/client.h +++ b/client.h @@ -62,6 +62,7 @@ struct Client Bool ftview; }; +void grabbuttons(Client *, Bool, Bool, KeySym, unsigned int); inline void attach(Client *); /* attaches c to global client list */ void ban(Client *); /* bans c */ void configure(Client *); /* send synthetic configure event */ diff --git a/event.c b/event.c index 4ba85a8e4..5d7994b31 100644 --- a/event.c +++ b/event.c @@ -201,9 +201,13 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) if((c = getclient(ev->window))) { focus(c->display, c, ev->same_screen, &awesomeconf[c->screen]); - if(CLEANMASK(ev->state, c->screen) != awesomeconf[c->screen].modkey) - return; - if(ev->button == Button1) + if(CLEANMASK(ev->state, c->screen) != awesomeconf[c->screen].modkey) { + if (ev->button == Button1) { + restack(c->display, &awesomeconf[c->screen]); + grabbuttons(c, True, True, awesomeconf->modkey, awesomeconf->numlockmask); + } + } + else if(ev->button == Button1) { if(!IS_ARRANGE(layout_floating) && !c->isfloating) uicb_togglefloating(e->xany.display, &awesomeconf[c->screen], NULL); @@ -341,8 +345,11 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf) if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) return; - if((c = getclient(ev->window))) + if((c = getclient(ev->window))) { focus(c->display, c, ev->same_screen, &awesomeconf[c->screen]); + if (sel) + grabbuttons(sel, True, False, awesomeconf->modkey, awesomeconf->numlockmask); + } else for(screen = 0; screen < ScreenCount(e->xany.display); screen++) if(ev->window == RootWindow(e->xany.display, screen))