move grabbuttons to window functions

This commit is contained in:
Julien Danjou 2007-10-26 19:45:33 +02:00
parent 47a878e4cd
commit e646072312
5 changed files with 111 additions and 101 deletions

103
client.c
View File

@ -47,97 +47,6 @@ get_client_bywin(Client *list, Window w)
return c; return 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
*/
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, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(c->display, Button1, modkey, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button1, modkey | LockMask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button1, modkey | numlockmask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button1, modkey | numlockmask | LockMask,
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button2, modkey, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button2, modkey | LockMask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button2, modkey | numlockmask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button2, modkey | numlockmask | LockMask,
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button3, modkey, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button3, modkey | LockMask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button3, modkey | numlockmask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button3, modkey | numlockmask | LockMask,
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, modkey, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, modkey | LockMask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, modkey | numlockmask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, modkey | numlockmask | LockMask,
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, modkey, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, modkey | LockMask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, modkey | numlockmask, c->win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, modkey | numlockmask | LockMask,
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XUngrabButton(c->display, AnyButton, AnyModifier, RootWindow(c->display, c->phys_screen));
}
else
{
XGrabButton(c->display, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, NoSymbol, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, numlockmask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button4, numlockmask | LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, NoSymbol, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, numlockmask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(c->display, Button5, numlockmask | LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
}
}
/** Check if client supports protocol WM_DELETE_WINDOW /** Check if client supports protocol WM_DELETE_WINDOW
* \param c the client * \param c the client
* \return True if client has WM_DELETE_WINDOW * \return True if client has WM_DELETE_WINDOW
@ -275,7 +184,10 @@ focus(Client *c, Bool selscreen, awesome_config *awesomeconf)
/* if a client was selected but it's not the current client, unfocus it */ /* if a client was selected but it's not the current client, unfocus it */
if(*awesomeconf->client_sel && *awesomeconf->client_sel != c) if(*awesomeconf->client_sel && *awesomeconf->client_sel != c)
{ {
grabbuttons(*awesomeconf->client_sel, False, True, awesomeconf->modkey, awesomeconf->numlockmask); window_grabbuttons((*awesomeconf->client_sel)->display,
(*awesomeconf->client_sel)->phys_screen,
(*awesomeconf->client_sel)->win,
False, True, awesomeconf->modkey, awesomeconf->numlockmask);
XSetWindowBorder(awesomeconf->display, (*awesomeconf->client_sel)->win, awesomeconf->colors_normal[ColBorder].pixel); XSetWindowBorder(awesomeconf->display, (*awesomeconf->client_sel)->win, awesomeconf->colors_normal[ColBorder].pixel);
window_settrans(awesomeconf->display, (*awesomeconf->client_sel)->win, awesomeconf->opacity_unfocused); window_settrans(awesomeconf->display, (*awesomeconf->client_sel)->win, awesomeconf->opacity_unfocused);
} }
@ -289,7 +201,8 @@ focus(Client *c, Bool selscreen, awesome_config *awesomeconf)
if(*awesomeconf->client_sel == c) if(*awesomeconf->client_sel == c)
return; return;
if(c) if(c)
grabbuttons(c, True, True, awesomeconf->modkey, awesomeconf->numlockmask); window_grabbuttons(c->display, c->phys_screen, c->win,
True, True, awesomeconf->modkey, awesomeconf->numlockmask);
if(!selscreen) if(!selscreen)
return; return;
*awesomeconf->client_sel = c; *awesomeconf->client_sel = c;
@ -415,8 +328,8 @@ manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf)
} }
/* grab buttons */ /* grab buttons */
window_grabbuttons(c->display, c->phys_screen, c->win,
grabbuttons(c, False, True, awesomeconf->modkey, awesomeconf->numlockmask); False, True, awesomeconf->modkey, awesomeconf->numlockmask);
/* update window title */ /* update window title */
updatetitle(c); updatetitle(c);

View File

@ -24,11 +24,7 @@
#include "common.h" #include "common.h"
/** Mask shorthands, used in event.c and client.c */
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
Client * get_client_bywin(Client *, Window); Client * get_client_bywin(Client *, Window);
void grabbuttons(Client *, Bool, Bool, KeySym, unsigned int);
inline void client_attach(Client **, Client *); inline void client_attach(Client **, Client *);
inline void client_detach(Client **, Client *); inline void client_detach(Client **, Client *);
void client_reattach_after(Client *, Client *); void client_reattach_after(Client *, Client *);

View File

@ -196,7 +196,8 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
if (ev->button == Button1) if (ev->button == Button1)
{ {
restack(&awesomeconf[c->screen]); restack(&awesomeconf[c->screen]);
grabbuttons(c, True, True, awesomeconf->modkey, awesomeconf->numlockmask); window_grabbuttons(c->display, c->phys_screen, c->win,
True, True, awesomeconf->modkey, awesomeconf->numlockmask);
} }
} }
else if(ev->button == Button1) else if(ev->button == Button1)
@ -361,7 +362,10 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf)
&& ((*awesomeconf->client_sel)->isfloating && ((*awesomeconf->client_sel)->isfloating
|| get_current_layout(awesomeconf[(*awesomeconf->client_sel)->screen].tags, || get_current_layout(awesomeconf[(*awesomeconf->client_sel)->screen].tags,
awesomeconf[(*awesomeconf->client_sel)->screen].ntags)->arrange == layout_floating)) awesomeconf[(*awesomeconf->client_sel)->screen].ntags)->arrange == layout_floating))
grabbuttons(*awesomeconf->client_sel, True, False, awesomeconf->modkey, awesomeconf->numlockmask); window_grabbuttons((*awesomeconf->client_sel)->display,
(*awesomeconf->client_sel)->phys_screen,
(*awesomeconf->client_sel)->win,
True, False, awesomeconf->modkey, awesomeconf->numlockmask);
} }
} }
else else

View File

@ -82,6 +82,99 @@ window_configure(Display *disp, Window win, int x, int y, int w, int h, int bord
return XSendEvent(disp, win, False, StructureNotifyMask, (XEvent *) & ce); return XSendEvent(disp, win, False, StructureNotifyMask, (XEvent *) & ce);
} }
/** Grab or ungrab buttons on a window
* \param disp Display ref
* \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
*/
void
window_grabbuttons(Display *disp, int screen, Window win, Bool focused, Bool raised, KeySym modkey, unsigned int numlockmask)
{
XUngrabButton(disp, AnyButton, AnyModifier, win);
if(focused)
{
if(!raised)
XGrabButton(disp, Button1, NoSymbol, win, False,
BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(disp, Button1, modkey, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button1, modkey | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button1, modkey | numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button1, modkey | numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button2, modkey, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button2, modkey | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button2, modkey | numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button2, modkey | numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button3, modkey, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button3, modkey | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button3, modkey | numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button3, modkey | numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, modkey, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, modkey | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, modkey | numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, modkey | numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, modkey, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, modkey | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, modkey | numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, modkey | numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XUngrabButton(disp, AnyButton, AnyModifier, RootWindow(disp, screen));
}
else
{
XGrabButton(disp, AnyButton, AnyModifier, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, NoSymbol, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, LockMask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, numlockmask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button4, numlockmask | LockMask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, NoSymbol, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, LockMask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, numlockmask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(disp, Button5, numlockmask | LockMask, RootWindow(disp, screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
}
}
void void
window_setshape(Display *disp, int screen, Window win) window_setshape(Display *disp, int screen, Window win)
{ {

View File

@ -24,9 +24,13 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
/** Mask shorthands, used in event.c and window.c */
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
int window_setstate(Display *, Window, long); int window_setstate(Display *, Window, long);
long window_getstate(Display *, Window); long window_getstate(Display *, Window);
Status window_configure(Display *, Window, int, int, int, int, int); Status window_configure(Display *, Window, int, int, int, int, int);
void window_grabbuttons(Display *, int, Window, Bool, Bool, KeySym, unsigned int);
void window_setshape(Display *, int, Window); void window_setshape(Display *, int, Window);
void window_settrans(Display *, Window, double); void window_settrans(Display *, Window, double);