We shouldn't enforce incr when the app resizes itself. But it's so confusing.
[mikachu/openbox.git] / openbox / edges.c
1 #include "openbox.h"
2 #include "config.h"
3 #include "screen.h"
4 #include "edges.h"
5
6 #include <X11/Xlib.h>
7 #include <glib.h>
8
9 #warning Do something clever with xinerama
10 ObEdge *edge[OB_NUM_EDGES];
11 #warning put in config.c and parse configs of course
12 gboolean config_edge_enabled[OB_NUM_EDGES] = {1, 1, 1, 1, 1, 1, 1, 1};
13
14 #ifdef DEBUG
15 #define EDGE_WIDTH 10
16 #define CORNER_SIZE 20
17 #else
18 #define EDGE_WIDTH 1
19 #define CORNER_SIZE 2
20 #endif
21 static void get_position(ObEdgeLocation edge, Rect screen, Rect *rect)
22 {
23     switch (edge) {
24         case OB_EDGE_TOP:
25             RECT_SET(*rect, CORNER_SIZE, 0,
26                      screen.width - 2 * CORNER_SIZE, EDGE_WIDTH);
27             break;
28         case OB_EDGE_TOPRIGHT:
29             RECT_SET(*rect, screen.width - CORNER_SIZE, 0,
30                      CORNER_SIZE, CORNER_SIZE);
31             break;
32         case OB_EDGE_RIGHT:
33             RECT_SET(*rect, screen.width - EDGE_WIDTH, CORNER_SIZE,
34                      EDGE_WIDTH, screen.height - 2 * CORNER_SIZE);
35             break;
36         case OB_EDGE_BOTTOMRIGHT:
37             RECT_SET(*rect, screen.width - CORNER_SIZE,
38                      screen.height - CORNER_SIZE,
39                      CORNER_SIZE, CORNER_SIZE);
40             break;
41         case OB_EDGE_BOTTOM:
42             RECT_SET(*rect, CORNER_SIZE, screen.height - EDGE_WIDTH,
43                      screen.width - 2 * CORNER_SIZE, EDGE_WIDTH);
44             break;
45         case OB_EDGE_BOTTOMLEFT:
46             RECT_SET(*rect, 0, screen.height - CORNER_SIZE,
47                      CORNER_SIZE, CORNER_SIZE);
48             break;
49         case OB_EDGE_LEFT:
50             RECT_SET(*rect, 0, CORNER_SIZE,
51                      EDGE_WIDTH, screen.height - CORNER_SIZE);
52             break;
53         case OB_EDGE_TOPLEFT:
54             RECT_SET(*rect, 0, 0, CORNER_SIZE, CORNER_SIZE);
55             break;
56     }
57 }
58
59 void edges_startup(gboolean reconfigure)
60 {
61     gint i;
62     Rect r;
63     XSetWindowAttributes xswa;
64     Rect *screen = screen_physical_area_all_monitors();
65
66     xswa.override_redirect = True;
67
68     for (i=0; i < OB_NUM_EDGES; i++) {
69         if (!config_edge_enabled[i])
70             continue;
71
72         edge[i] = g_new(ObEdge, 1);
73         edge[i]->obwin.type = OB_WINDOW_CLASS_INTERNAL;
74
75         get_position(i, *screen, &r);
76         edge[i]->win = XCreateWindow(obt_display, RootWindow(obt_display, ob_screen),
77                                      r.x, r.y, r.width, r.height, 0, 0, InputOnly,
78                                      CopyFromParent, CWOverrideRedirect, &xswa);
79         XMapWindow(obt_display, edge[i]->win);
80
81         stacking_add(INTERNAL_AS_WINDOW(edge[i]));
82         window_add(&edge[i]->win, INTERNAL_AS_WINDOW(edge[i]));
83
84 #ifdef DEBUG
85         printf("mapped edge window %i at %03i %03i %02i %02i\n", i, r.x, r.y, r.width, r.height);
86         fflush(stdout);
87 #endif
88     }
89
90     XFlush(obt_display);
91
92     g_free(screen);
93 }
94
95 void edges_shutdown(gboolean reconfigure)
96 {
97     gint i;
98
99     for (i=0; i < OB_NUM_EDGES; i++) {
100         window_remove(edge[i]->win);
101         stacking_remove(INTERNAL_AS_WINDOW(edge[i]));
102         XDestroyWindow(obt_display, edge[i]->win);
103         g_free(edge[i]);
104     }
105 }