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"
25 #include "render/render.h"
30 #define FOCUS_INDICATOR_WIDTH 6
37 InternalWindow bottom
;
40 static RrAppearance
*a_focus_indicator
;
41 static RrColor
*color_white
;
42 static gboolean visible
;
44 static Window
create_window(Window parent
, gulong mask
,
45 XSetWindowAttributes
*attrib
)
47 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
48 RrDepth(ob_rr_inst
), InputOutput
,
49 RrVisual(ob_rr_inst
), mask
, attrib
);
53 void focus_cycle_indicator_startup(gboolean reconfig
)
55 XSetWindowAttributes attr
;
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
;
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
);
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
);
94 color_white
= RrColorNew(ob_rr_inst
, 0xff, 0xff, 0xff);
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
,
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
;
111 void focus_cycle_indicator_shutdown(gboolean reconfig
)
113 if (reconfig
) return;
115 RrColorFree(color_white
);
117 RrAppearanceFree(a_focus_indicator
);
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
);
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
));
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
);
135 void focus_cycle_draw_indicator(ObClient
*c
)
140 /* kill enter events cause by this unmapping */
141 ignore_start
= event_start_ignore_all_enters();
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
);
148 event_end_ignore_all_enters(ignore_start
);
155 frame_adjust_focus(c->frame, FALSE);
156 frame_adjust_focus(c->frame, TRUE);
161 wt
= wl
= wr
= wb
= FOCUS_INDICATOR_WIDTH
;
163 x
= c
->frame
->area
.x
;
164 y
= c
->frame
->area
.y
;
165 w
= c
->frame
->area
.width
;
168 XMoveResizeWindow(ob_display
, focus_indicator
.top
.win
,
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
,
189 x
= c
->frame
->area
.x
;
190 y
= c
->frame
->area
.y
;
192 h
= c
->frame
->area
.height
;
194 XMoveResizeWindow(ob_display
, focus_indicator
.left
.win
,
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
,
215 x
= c
->frame
->area
.x
+ c
->frame
->area
.width
- wr
;
216 y
= c
->frame
->area
.y
;
218 h
= c
->frame
->area
.height
;
220 XMoveResizeWindow(ob_display
, focus_indicator
.right
.win
,
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
,
241 x
= c
->frame
->area
.x
;
242 y
= c
->frame
->area
.y
+ c
->frame
->area
.height
- wb
;
243 w
= c
->frame
->area
.width
;
246 XMoveResizeWindow(ob_display
, focus_indicator
.bottom
.win
,
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
,
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
);