1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 focus_cycle_indicator.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
20 #include "focus_cycle.h"
21 #include "focus_cycle_indicator.h"
26 #include "render/render.h"
31 #define FOCUS_INDICATOR_WIDTH 6
38 InternalWindow bottom
;
41 static RrAppearance
*a_focus_indicator
;
42 static RrColor
*color_white
;
43 static gboolean visible
;
45 static Window
create_window(Window parent
, gulong mask
,
46 XSetWindowAttributes
*attrib
)
48 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
49 RrDepth(ob_rr_inst
), InputOutput
,
50 RrVisual(ob_rr_inst
), mask
, attrib
);
54 void focus_cycle_indicator_startup(gboolean reconfig
)
56 XSetWindowAttributes attr
;
62 focus_indicator
.top
.type
= Window_Internal
;
63 focus_indicator
.left
.type
= Window_Internal
;
64 focus_indicator
.right
.type
= Window_Internal
;
65 focus_indicator
.bottom
.type
= Window_Internal
;
67 attr
.override_redirect
= True
;
68 attr
.background_pixel
= BlackPixel(ob_display
, ob_screen
);
69 focus_indicator
.top
.window
=
70 create_window(RootWindow(ob_display
, ob_screen
),
71 CWOverrideRedirect
| CWBackPixel
, &attr
);
72 focus_indicator
.left
.window
=
73 create_window(RootWindow(ob_display
, ob_screen
),
74 CWOverrideRedirect
| CWBackPixel
, &attr
);
75 focus_indicator
.right
.window
=
76 create_window(RootWindow(ob_display
, ob_screen
),
77 CWOverrideRedirect
| CWBackPixel
, &attr
);
78 focus_indicator
.bottom
.window
=
79 create_window(RootWindow(ob_display
, ob_screen
),
80 CWOverrideRedirect
| CWBackPixel
, &attr
);
82 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.top
));
83 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.left
));
84 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.right
));
85 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.bottom
));
86 g_hash_table_insert(window_map
, &focus_indicator
.top
.window
,
87 &focus_indicator
.top
);
88 g_hash_table_insert(window_map
, &focus_indicator
.left
.window
,
89 &focus_indicator
.left
);
90 g_hash_table_insert(window_map
, &focus_indicator
.right
.window
,
91 &focus_indicator
.right
);
92 g_hash_table_insert(window_map
, &focus_indicator
.bottom
.window
,
93 &focus_indicator
.bottom
);
95 color_white
= RrColorNew(ob_rr_inst
, 0xff, 0xff, 0xff);
97 a_focus_indicator
= RrAppearanceNew(ob_rr_inst
, 4);
98 a_focus_indicator
->surface
.grad
= RR_SURFACE_SOLID
;
99 a_focus_indicator
->surface
.relief
= RR_RELIEF_FLAT
;
100 a_focus_indicator
->surface
.primary
= RrColorNew(ob_rr_inst
,
102 a_focus_indicator
->texture
[0].type
= RR_TEXTURE_LINE_ART
;
103 a_focus_indicator
->texture
[0].data
.lineart
.color
= color_white
;
104 a_focus_indicator
->texture
[1].type
= RR_TEXTURE_LINE_ART
;
105 a_focus_indicator
->texture
[1].data
.lineart
.color
= color_white
;
106 a_focus_indicator
->texture
[2].type
= RR_TEXTURE_LINE_ART
;
107 a_focus_indicator
->texture
[2].data
.lineart
.color
= color_white
;
108 a_focus_indicator
->texture
[3].type
= RR_TEXTURE_LINE_ART
;
109 a_focus_indicator
->texture
[3].data
.lineart
.color
= color_white
;
112 void focus_cycle_indicator_shutdown(gboolean reconfig
)
114 if (reconfig
) return;
116 RrColorFree(color_white
);
118 RrAppearanceFree(a_focus_indicator
);
120 g_hash_table_remove(window_map
, &focus_indicator
.top
.window
);
121 g_hash_table_remove(window_map
, &focus_indicator
.left
.window
);
122 g_hash_table_remove(window_map
, &focus_indicator
.right
.window
);
123 g_hash_table_remove(window_map
, &focus_indicator
.bottom
.window
);
125 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.top
));
126 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.left
));
127 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.right
));
128 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.bottom
));
130 XDestroyWindow(ob_display
, focus_indicator
.top
.window
);
131 XDestroyWindow(ob_display
, focus_indicator
.left
.window
);
132 XDestroyWindow(ob_display
, focus_indicator
.right
.window
);
133 XDestroyWindow(ob_display
, focus_indicator
.bottom
.window
);
136 void focus_cycle_update_indicator(ObClient
*c
)
139 focus_cycle_draw_indicator(c
);
142 void focus_cycle_draw_indicator(ObClient
*c
)
147 /* kill enter events cause by this unmapping */
148 ignore_start
= event_start_ignore_all_enters();
150 XUnmapWindow(ob_display
, focus_indicator
.top
.window
);
151 XUnmapWindow(ob_display
, focus_indicator
.left
.window
);
152 XUnmapWindow(ob_display
, focus_indicator
.right
.window
);
153 XUnmapWindow(ob_display
, focus_indicator
.bottom
.window
);
155 event_end_ignore_all_enters(ignore_start
);
162 frame_adjust_focus(c->frame, FALSE);
163 frame_adjust_focus(c->frame, TRUE);
169 wt
= wl
= wr
= wb
= FOCUS_INDICATOR_WIDTH
;
171 x
= c
->frame
->area
.x
;
172 y
= c
->frame
->area
.y
;
173 w
= c
->frame
->area
.width
;
176 /* kill enter events cause by this moving */
177 ignore_start
= event_start_ignore_all_enters();
179 XMoveResizeWindow(ob_display
, focus_indicator
.top
.window
,
181 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
182 a_focus_indicator
->texture
[0].data
.lineart
.y1
= h
-1;
183 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
184 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
185 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
186 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
187 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
188 a_focus_indicator
->texture
[1].data
.lineart
.y2
= 0;
189 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
190 a_focus_indicator
->texture
[2].data
.lineart
.y1
= 0;
191 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
192 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
193 a_focus_indicator
->texture
[3].data
.lineart
.x1
= (wl
-1);
194 a_focus_indicator
->texture
[3].data
.lineart
.y1
= h
-1;
195 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
196 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
-1;
197 RrPaint(a_focus_indicator
, focus_indicator
.top
.window
,
200 x
= c
->frame
->area
.x
;
201 y
= c
->frame
->area
.y
;
203 h
= c
->frame
->area
.height
;
205 XMoveResizeWindow(ob_display
, focus_indicator
.left
.window
,
207 a_focus_indicator
->texture
[0].data
.lineart
.x1
= w
-1;
208 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
209 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
210 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
211 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
212 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
213 a_focus_indicator
->texture
[1].data
.lineart
.x2
= 0;
214 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
215 a_focus_indicator
->texture
[2].data
.lineart
.x1
= 0;
216 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
217 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
218 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
219 a_focus_indicator
->texture
[3].data
.lineart
.x1
= w
-1;
220 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
221 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
-1;
222 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
223 RrPaint(a_focus_indicator
, focus_indicator
.left
.window
,
226 x
= c
->frame
->area
.x
+ c
->frame
->area
.width
- wr
;
227 y
= c
->frame
->area
.y
;
229 h
= c
->frame
->area
.height
;
231 XMoveResizeWindow(ob_display
, focus_indicator
.right
.window
,
233 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
234 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
235 a_focus_indicator
->texture
[0].data
.lineart
.x2
= w
-1;
236 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
237 a_focus_indicator
->texture
[1].data
.lineart
.x1
= w
-1;
238 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
239 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
240 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
241 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
242 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
243 a_focus_indicator
->texture
[2].data
.lineart
.x2
= 0;
244 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
245 a_focus_indicator
->texture
[3].data
.lineart
.x1
= 0;
246 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
247 a_focus_indicator
->texture
[3].data
.lineart
.x2
= 0;
248 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
249 RrPaint(a_focus_indicator
, focus_indicator
.right
.window
,
252 x
= c
->frame
->area
.x
;
253 y
= c
->frame
->area
.y
+ c
->frame
->area
.height
- wb
;
254 w
= c
->frame
->area
.width
;
257 XMoveResizeWindow(ob_display
, focus_indicator
.bottom
.window
,
259 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
260 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
261 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
262 a_focus_indicator
->texture
[0].data
.lineart
.y2
= h
-1;
263 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
264 a_focus_indicator
->texture
[1].data
.lineart
.y1
= h
-1;
265 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
266 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
267 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
268 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
269 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
270 a_focus_indicator
->texture
[2].data
.lineart
.y2
= 0;
271 a_focus_indicator
->texture
[3].data
.lineart
.x1
= wl
-1;
272 a_focus_indicator
->texture
[3].data
.lineart
.y1
= 0;
273 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
274 a_focus_indicator
->texture
[3].data
.lineart
.y2
= 0;
275 RrPaint(a_focus_indicator
, focus_indicator
.bottom
.window
,
278 XMapWindow(ob_display
, focus_indicator
.top
.window
);
279 XMapWindow(ob_display
, focus_indicator
.left
.window
);
280 XMapWindow(ob_display
, focus_indicator
.right
.window
);
281 XMapWindow(ob_display
, focus_indicator
.bottom
.window
);
283 event_end_ignore_all_enters(ignore_start
);