]> Dogcows Code - chaz/openbox/blob - openbox/focus_cycle_indicator.c
make the focus cycle indicator be in the window_map so button presses on it are handl...
[chaz/openbox] / openbox / focus_cycle_indicator.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 focus_cycle_indicator.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "focus_cycle.h"
21 #include "client.h"
22 #include "openbox.h"
23 #include "frame.h"
24 #include "event.h"
25 #include "render/render.h"
26
27 #include <X11/Xlib.h>
28 #include <glib.h>
29
30 #define FOCUS_INDICATOR_WIDTH 6
31
32 struct
33 {
34 InternalWindow top;
35 InternalWindow left;
36 InternalWindow right;
37 InternalWindow bottom;
38 } focus_indicator;
39
40 static RrAppearance *a_focus_indicator;
41 static RrColor *color_white;
42 static gboolean visible;
43
44 static Window create_window(Window parent, gulong mask,
45 XSetWindowAttributes *attrib)
46 {
47 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
48 RrDepth(ob_rr_inst), InputOutput,
49 RrVisual(ob_rr_inst), mask, attrib);
50
51 }
52
53 void focus_cycle_indicator_startup(gboolean reconfig)
54 {
55 XSetWindowAttributes attr;
56
57 visible = FALSE;
58
59 if (reconfig) return;
60
61 focus_indicator.top.obwin.type = Window_Internal;
62 focus_indicator.left.obwin.type = Window_Internal;
63 focus_indicator.right.obwin.type = Window_Internal;
64 focus_indicator.bottom.obwin.type = Window_Internal;
65
66 attr.override_redirect = True;
67 attr.background_pixel = BlackPixel(ob_display, ob_screen);
68 focus_indicator.top.win =
69 create_window(RootWindow(ob_display, ob_screen),
70 CWOverrideRedirect | CWBackPixel, &attr);
71 focus_indicator.left.win =
72 create_window(RootWindow(ob_display, ob_screen),
73 CWOverrideRedirect | CWBackPixel, &attr);
74 focus_indicator.right.win =
75 create_window(RootWindow(ob_display, ob_screen),
76 CWOverrideRedirect | CWBackPixel, &attr);
77 focus_indicator.bottom.win =
78 create_window(RootWindow(ob_display, ob_screen),
79 CWOverrideRedirect | CWBackPixel, &attr);
80
81 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.top));
82 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.left));
83 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.right));
84 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.bottom));
85 g_hash_table_insert(window_map, &focus_indicator.top.win,
86 &focus_indicator.top);
87 g_hash_table_insert(window_map, &focus_indicator.left.win,
88 &focus_indicator.left);
89 g_hash_table_insert(window_map, &focus_indicator.right.win,
90 &focus_indicator.right);
91 g_hash_table_insert(window_map, &focus_indicator.bottom.win,
92 &focus_indicator.bottom);
93
94 color_white = RrColorNew(ob_rr_inst, 0xff, 0xff, 0xff);
95
96 a_focus_indicator = RrAppearanceNew(ob_rr_inst, 4);
97 a_focus_indicator->surface.grad = RR_SURFACE_SOLID;
98 a_focus_indicator->surface.relief = RR_RELIEF_FLAT;
99 a_focus_indicator->surface.primary = RrColorNew(ob_rr_inst,
100 0, 0, 0);
101 a_focus_indicator->texture[0].type = RR_TEXTURE_LINE_ART;
102 a_focus_indicator->texture[0].data.lineart.color = color_white;
103 a_focus_indicator->texture[1].type = RR_TEXTURE_LINE_ART;
104 a_focus_indicator->texture[1].data.lineart.color = color_white;
105 a_focus_indicator->texture[2].type = RR_TEXTURE_LINE_ART;
106 a_focus_indicator->texture[2].data.lineart.color = color_white;
107 a_focus_indicator->texture[3].type = RR_TEXTURE_LINE_ART;
108 a_focus_indicator->texture[3].data.lineart.color = color_white;
109 }
110
111 void focus_cycle_indicator_shutdown(gboolean reconfig)
112 {
113 if (reconfig) return;
114
115 RrColorFree(color_white);
116
117 RrAppearanceFree(a_focus_indicator);
118
119 g_hash_table_remove(window_map, &focus_indicator.top.win);
120 g_hash_table_remove(window_map, &focus_indicator.left.win);
121 g_hash_table_remove(window_map, &focus_indicator.right.win);
122 g_hash_table_remove(window_map, &focus_indicator.bottom.win);
123
124 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.top));
125 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.left));
126 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.right));
127 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.bottom));
128
129 XDestroyWindow(ob_display, focus_indicator.top.win);
130 XDestroyWindow(ob_display, focus_indicator.left.win);
131 XDestroyWindow(ob_display, focus_indicator.right.win);
132 XDestroyWindow(ob_display, focus_indicator.bottom.win);
133 }
134
135 void focus_cycle_draw_indicator(ObClient *c)
136 {
137 if (!c && visible) {
138 gulong ignore_start;
139
140 /* kill enter events cause by this unmapping */
141 ignore_start = event_start_ignore_all_enters();
142
143 XUnmapWindow(ob_display, focus_indicator.top.win);
144 XUnmapWindow(ob_display, focus_indicator.left.win);
145 XUnmapWindow(ob_display, focus_indicator.right.win);
146 XUnmapWindow(ob_display, focus_indicator.bottom.win);
147
148 event_end_ignore_all_enters(ignore_start);
149
150 visible = FALSE;
151 }
152 else if (c) {
153 /*
154 if (c)
155 frame_adjust_focus(c->frame, FALSE);
156 frame_adjust_focus(c->frame, TRUE);
157 */
158 gint x, y, w, h;
159 gint wt, wl, wr, wb;
160
161 wt = wl = wr = wb = FOCUS_INDICATOR_WIDTH;
162
163 x = c->frame->area.x;
164 y = c->frame->area.y;
165 w = c->frame->area.width;
166 h = wt;
167
168 XMoveResizeWindow(ob_display, focus_indicator.top.win,
169 x, y, w, h);
170 a_focus_indicator->texture[0].data.lineart.x1 = 0;
171 a_focus_indicator->texture[0].data.lineart.y1 = h-1;
172 a_focus_indicator->texture[0].data.lineart.x2 = 0;
173 a_focus_indicator->texture[0].data.lineart.y2 = 0;
174 a_focus_indicator->texture[1].data.lineart.x1 = 0;
175 a_focus_indicator->texture[1].data.lineart.y1 = 0;
176 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
177 a_focus_indicator->texture[1].data.lineart.y2 = 0;
178 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
179 a_focus_indicator->texture[2].data.lineart.y1 = 0;
180 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
181 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
182 a_focus_indicator->texture[3].data.lineart.x1 = (wl-1);
183 a_focus_indicator->texture[3].data.lineart.y1 = h-1;
184 a_focus_indicator->texture[3].data.lineart.x2 = w - wr;
185 a_focus_indicator->texture[3].data.lineart.y2 = h-1;
186 RrPaint(a_focus_indicator, focus_indicator.top.win,
187 w, h);
188
189 x = c->frame->area.x;
190 y = c->frame->area.y;
191 w = wl;
192 h = c->frame->area.height;
193
194 XMoveResizeWindow(ob_display, focus_indicator.left.win,
195 x, y, w, h);
196 a_focus_indicator->texture[0].data.lineart.x1 = w-1;
197 a_focus_indicator->texture[0].data.lineart.y1 = 0;
198 a_focus_indicator->texture[0].data.lineart.x2 = 0;
199 a_focus_indicator->texture[0].data.lineart.y2 = 0;
200 a_focus_indicator->texture[1].data.lineart.x1 = 0;
201 a_focus_indicator->texture[1].data.lineart.y1 = 0;
202 a_focus_indicator->texture[1].data.lineart.x2 = 0;
203 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
204 a_focus_indicator->texture[2].data.lineart.x1 = 0;
205 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
206 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
207 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
208 a_focus_indicator->texture[3].data.lineart.x1 = w-1;
209 a_focus_indicator->texture[3].data.lineart.y1 = wt-1;
210 a_focus_indicator->texture[3].data.lineart.x2 = w-1;
211 a_focus_indicator->texture[3].data.lineart.y2 = h - wb;
212 RrPaint(a_focus_indicator, focus_indicator.left.win,
213 w, h);
214
215 x = c->frame->area.x + c->frame->area.width - wr;
216 y = c->frame->area.y;
217 w = wr;
218 h = c->frame->area.height ;
219
220 XMoveResizeWindow(ob_display, focus_indicator.right.win,
221 x, y, w, h);
222 a_focus_indicator->texture[0].data.lineart.x1 = 0;
223 a_focus_indicator->texture[0].data.lineart.y1 = 0;
224 a_focus_indicator->texture[0].data.lineart.x2 = w-1;
225 a_focus_indicator->texture[0].data.lineart.y2 = 0;
226 a_focus_indicator->texture[1].data.lineart.x1 = w-1;
227 a_focus_indicator->texture[1].data.lineart.y1 = 0;
228 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
229 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
230 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
231 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
232 a_focus_indicator->texture[2].data.lineart.x2 = 0;
233 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
234 a_focus_indicator->texture[3].data.lineart.x1 = 0;
235 a_focus_indicator->texture[3].data.lineart.y1 = wt-1;
236 a_focus_indicator->texture[3].data.lineart.x2 = 0;
237 a_focus_indicator->texture[3].data.lineart.y2 = h - wb;
238 RrPaint(a_focus_indicator, focus_indicator.right.win,
239 w, h);
240
241 x = c->frame->area.x;
242 y = c->frame->area.y + c->frame->area.height - wb;
243 w = c->frame->area.width;
244 h = wb;
245
246 XMoveResizeWindow(ob_display, focus_indicator.bottom.win,
247 x, y, w, h);
248 a_focus_indicator->texture[0].data.lineart.x1 = 0;
249 a_focus_indicator->texture[0].data.lineart.y1 = 0;
250 a_focus_indicator->texture[0].data.lineart.x2 = 0;
251 a_focus_indicator->texture[0].data.lineart.y2 = h-1;
252 a_focus_indicator->texture[1].data.lineart.x1 = 0;
253 a_focus_indicator->texture[1].data.lineart.y1 = h-1;
254 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
255 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
256 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
257 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
258 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
259 a_focus_indicator->texture[2].data.lineart.y2 = 0;
260 a_focus_indicator->texture[3].data.lineart.x1 = wl-1;
261 a_focus_indicator->texture[3].data.lineart.y1 = 0;
262 a_focus_indicator->texture[3].data.lineart.x2 = w - wr;
263 a_focus_indicator->texture[3].data.lineart.y2 = 0;
264 RrPaint(a_focus_indicator, focus_indicator.bottom.win,
265 w, h);
266
267 XMapWindow(ob_display, focus_indicator.top.win);
268 XMapWindow(ob_display, focus_indicator.left.win);
269 XMapWindow(ob_display, focus_indicator.right.win);
270 XMapWindow(ob_display, focus_indicator.bottom.win);
271
272 visible = TRUE;
273 }
274 }
This page took 0.049247 seconds and 5 git commands to generate.