Move signal re-registration to the end of the signal handler
[dvtm.git] / mouse.c
blob52a6508fe42d6974735a410f85ba5cfc55bc7aa3
1 static Client *msel = NULL;
3 static void
4 mouse_focus(const char *args[]) {
5 focus(msel);
6 if (msel->minimized)
7 toggleminimize(NULL);
10 static void
11 mouse_fullscreen(const char *args[]) {
12 mouse_focus(NULL);
13 if (isarrange(fullscreen))
14 setlayout(NULL);
15 else
16 setlayout(args);
19 static void
20 mouse_minimize(const char *args[]) {
21 focus(msel);
22 toggleminimize(NULL);
25 static void
26 mouse_zoom(const char *args[]) {
27 focus(msel);
28 zoom(NULL);
31 static Client*
32 get_client_by_coord(int x, int y) {
33 Client *c;
34 if (y < way || y >= wah)
35 return NULL;
36 if (isarrange(fullscreen))
37 return sel;
38 for (c = clients; c; c = c->next) {
39 if (x >= c->x && x < c->x + c->w && y >= c->y && y < c->y + c->h) {
40 debug("mouse event, x: %d y: %d client: %d\n", x, y, c->order);
41 return c;
44 return NULL;
47 static void
48 handle_mouse() {
49 MEVENT event;
50 unsigned int i;
51 if (getmouse(&event) != OK)
52 return;
53 msel = get_client_by_coord(event.x, event.y);
54 if (!msel)
55 return;
56 for (i = 0; i < countof(buttons); i++)
57 if (event.bstate & buttons[i].mask)
58 buttons[i].action.cmd(buttons[i].action.args);
59 msel = NULL;
62 static void
63 mouse_setup() {
64 int i;
65 mmask_t mask;
66 for (i = 0, mask = 0; i < countof(buttons); i++)
67 mask |= buttons[i].mask;
68 if (mask)
69 mousemask(mask, NULL);
72 static void
73 mouse_toggle() {
74 static int state = 0;
75 if(!state)
76 mousemask(0, NULL);
77 else
78 mouse_setup();
79 state = !state;