-
Notifications
You must be signed in to change notification settings - Fork 6
/
autohide_main.c
109 lines (91 loc) · 2.79 KB
/
autohide_main.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "autohide.h"
#include "autohide_aux.c"
Window *getBar(xdo_t *xdo) {
Window *bar = NULL;
Window **list = malloc(sizeof(Window *) * 20);
xdo_search_t query;
unsigned int n_win = 0;
// initialize query to find bar window
memset(&query, 0, sizeof(xdo_search_t));
query.max_depth = -1;
query.require = SEARCH_ANY;
query.searchmask |= SEARCH_CLASS;
query.winclass = BAR_WM_CLASS;
xdo_search_windows(xdo, &query, list, &n_win);
bar = list[0];
free(list);
return bar;
}
int activeWindowIsFullscreen(xdo_t *xdo) {
int fullscreen = 0;
Window window;
long nitems;
unsigned char *states;
int ret = xdo_get_active_window(xdo, &window);
if (ret == XDO_ERROR || window == 0)
fail("ERROR: xdo_get_active_window");
ret = xdo_get_window_property(xdo, window, "_NET_WM_STATE", &states, &nitems, NULL, NULL);
if (ret == XDO_ERROR)
fail("ERROR: xdo_get_window_property");
char *state;
for (int i = 0; i < nitems; ++i) {
state = XGetAtomName(xdo->xdpy, ((Atom*)states)[i]);
if (strcmp(state, "_NET_WM_STATE_FULLSCREEN") == 0)
fullscreen = 1;
XFree(state);
}
free(states);
return fullscreen;
}
int main(){
// init xdo
xdo_t *xdo = xdo_new(NULL);
if (xdo == NULL) {
fail("ERROR: Failed to initialize xdo");
}
// get bar window object
Window *bar = getBar(xdo);
if (bar == NULL) {
fail("ERROR: Failed to find bar");
}
// main loop
int y = 0;
bool hidden = false;
while (1) {
// check if active window is fullscreen
if (hidden && CHECK_FULLSCREEN && activeWindowIsFullscreen(xdo)) {
usleep(LOOP_DELAY * 1000);
continue;
}
// get mouse location
xdo_get_mouse_location(xdo, NULL, &y, NULL);
// if mouse is not in top or bottom bar
if (y > MARGIN_HIDE_TOP && y < MARGIN_HIDE_BOTTOM) {
if (!hidden) {
xdo_unmap_window(xdo, *bar);
hidden = true;
}
usleep(CURSOR_WINDOW_DELAY * 1000);
continue;
}
// if mouse is in top bar
else if (y < MARGIN_TOP && USE_TOP_BAR == 1) {
// if mouse is in top bar and bar is hidden
usleep(CURSOR_WINDOW_DELAY * 1000);
xdo_map_window(xdo, *bar);
hidden = false;
continue;
}
// if mouse is in bottom bar
else if (y > MARGIN_BOTTOM && USE_BOTTOM_BAR == 1) {
// if mouse is in bottom bar and bar is hidden
usleep(CURSOR_WINDOW_DELAY * 1000);
xdo_map_window(xdo, *bar);
hidden = false;
continue;
}
usleep(LOOP_DELAY);
}
xdo_free(xdo);
return 0;
}