-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse.c
More file actions
80 lines (72 loc) · 1.38 KB
/
mouse.c
File metadata and controls
80 lines (72 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
static Client *msel = NULL;
static void
mouse_focus(const char *args[]) {
focus(msel);
if (msel->minimized)
toggleminimize(NULL);
}
static void
mouse_fullscreen(const char *args[]) {
mouse_focus(NULL);
if (isarrange(fullscreen))
setlayout(NULL);
else
setlayout(args);
}
static void
mouse_minimize(const char *args[]) {
focus(msel);
toggleminimize(NULL);
}
static void
mouse_zoom(const char *args[]) {
focus(msel);
zoom(NULL);
}
static Client*
get_client_by_coord(int x, int y) {
Client *c;
if (y < way || y >= wah)
return NULL;
if (isarrange(fullscreen))
return sel;
for (c = clients; c; c = c->next) {
if (x >= c->x && x < c->x + c->w && y >= c->y && y < c->y + c->h) {
debug("mouse event, x: %d y: %d client: %d\n", x, y, c->order);
return c;
}
}
return NULL;
}
static void
handle_mouse() {
MEVENT event;
unsigned int i;
if (getmouse(&event) != OK)
return;
msel = get_client_by_coord(event.x, event.y);
if (!msel)
return;
for (i = 0; i < countof(buttons); i++)
if (event.bstate & buttons[i].mask)
buttons[i].action.cmd(buttons[i].action.args);
msel = NULL;
}
static void
mouse_setup() {
int i;
mmask_t mask;
for (i = 0, mask = 0; i < countof(buttons); i++)
mask |= buttons[i].mask;
if (mask)
mousemask(mask, NULL);
}
static void
mouse_toggle() {
static int state = 0;
if(!state)
mousemask(0, NULL);
else
mouse_setup();
state = !state;
}