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
));
86 color_white
= RrColorNew(ob_rr_inst
, 0xff, 0xff, 0xff);
88 a_focus_indicator
= RrAppearanceNew(ob_rr_inst
, 4);
89 a_focus_indicator
->surface
.grad
= RR_SURFACE_SOLID
;
90 a_focus_indicator
->surface
.relief
= RR_RELIEF_FLAT
;
91 a_focus_indicator
->surface
.primary
= RrColorNew(ob_rr_inst
,
93 a_focus_indicator
->texture
[0].type
= RR_TEXTURE_LINE_ART
;
94 a_focus_indicator
->texture
[0].data
.lineart
.color
= color_white
;
95 a_focus_indicator
->texture
[1].type
= RR_TEXTURE_LINE_ART
;
96 a_focus_indicator
->texture
[1].data
.lineart
.color
= color_white
;
97 a_focus_indicator
->texture
[2].type
= RR_TEXTURE_LINE_ART
;
98 a_focus_indicator
->texture
[2].data
.lineart
.color
= color_white
;
99 a_focus_indicator
->texture
[3].type
= RR_TEXTURE_LINE_ART
;
100 a_focus_indicator
->texture
[3].data
.lineart
.color
= color_white
;
103 void focus_cycle_indicator_shutdown(gboolean reconfig
)
105 if (reconfig
) return;
107 RrColorFree(color_white
);
109 RrAppearanceFree(a_focus_indicator
);
111 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.top
));
112 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.left
));
113 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.right
));
114 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.bottom
));
116 XDestroyWindow(ob_display
, focus_indicator
.top
.win
);
117 XDestroyWindow(ob_display
, focus_indicator
.left
.win
);
118 XDestroyWindow(ob_display
, focus_indicator
.right
.win
);
119 XDestroyWindow(ob_display
, focus_indicator
.bottom
.win
);
122 void focus_cycle_draw_indicator(ObClient
*c
)
127 /* kill enter events cause by this unmapping */
128 ignore_start
= event_start_ignore_all_enters();
130 XUnmapWindow(ob_display
, focus_indicator
.top
.win
);
131 XUnmapWindow(ob_display
, focus_indicator
.left
.win
);
132 XUnmapWindow(ob_display
, focus_indicator
.right
.win
);
133 XUnmapWindow(ob_display
, focus_indicator
.bottom
.win
);
135 event_end_ignore_all_enters(ignore_start
);
142 frame_adjust_focus(c->frame, FALSE);
143 frame_adjust_focus(c->frame, TRUE);
148 wt
= wl
= wr
= wb
= FOCUS_INDICATOR_WIDTH
;
150 x
= c
->frame
->area
.x
;
151 y
= c
->frame
->area
.y
;
152 w
= c
->frame
->area
.width
;
155 XMoveResizeWindow(ob_display
, focus_indicator
.top
.win
,
157 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
158 a_focus_indicator
->texture
[0].data
.lineart
.y1
= h
-1;
159 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
160 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
161 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
162 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
163 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
164 a_focus_indicator
->texture
[1].data
.lineart
.y2
= 0;
165 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
166 a_focus_indicator
->texture
[2].data
.lineart
.y1
= 0;
167 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
168 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
169 a_focus_indicator
->texture
[3].data
.lineart
.x1
= (wl
-1);
170 a_focus_indicator
->texture
[3].data
.lineart
.y1
= h
-1;
171 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
172 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
-1;
173 RrPaint(a_focus_indicator
, focus_indicator
.top
.win
,
176 x
= c
->frame
->area
.x
;
177 y
= c
->frame
->area
.y
;
179 h
= c
->frame
->area
.height
;
181 XMoveResizeWindow(ob_display
, focus_indicator
.left
.win
,
183 a_focus_indicator
->texture
[0].data
.lineart
.x1
= w
-1;
184 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
185 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
186 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
187 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
188 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
189 a_focus_indicator
->texture
[1].data
.lineart
.x2
= 0;
190 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
191 a_focus_indicator
->texture
[2].data
.lineart
.x1
= 0;
192 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
193 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
194 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
195 a_focus_indicator
->texture
[3].data
.lineart
.x1
= w
-1;
196 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
197 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
-1;
198 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
199 RrPaint(a_focus_indicator
, focus_indicator
.left
.win
,
202 x
= c
->frame
->area
.x
+ c
->frame
->area
.width
- wr
;
203 y
= c
->frame
->area
.y
;
205 h
= c
->frame
->area
.height
;
207 XMoveResizeWindow(ob_display
, focus_indicator
.right
.win
,
209 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
210 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
211 a_focus_indicator
->texture
[0].data
.lineart
.x2
= w
-1;
212 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
213 a_focus_indicator
->texture
[1].data
.lineart
.x1
= w
-1;
214 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
215 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
216 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
217 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
218 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
219 a_focus_indicator
->texture
[2].data
.lineart
.x2
= 0;
220 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
221 a_focus_indicator
->texture
[3].data
.lineart
.x1
= 0;
222 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
223 a_focus_indicator
->texture
[3].data
.lineart
.x2
= 0;
224 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
225 RrPaint(a_focus_indicator
, focus_indicator
.right
.win
,
228 x
= c
->frame
->area
.x
;
229 y
= c
->frame
->area
.y
+ c
->frame
->area
.height
- wb
;
230 w
= c
->frame
->area
.width
;
233 XMoveResizeWindow(ob_display
, focus_indicator
.bottom
.win
,
235 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
236 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
237 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
238 a_focus_indicator
->texture
[0].data
.lineart
.y2
= h
-1;
239 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
240 a_focus_indicator
->texture
[1].data
.lineart
.y1
= h
-1;
241 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
242 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
243 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
244 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
245 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
246 a_focus_indicator
->texture
[2].data
.lineart
.y2
= 0;
247 a_focus_indicator
->texture
[3].data
.lineart
.x1
= wl
-1;
248 a_focus_indicator
->texture
[3].data
.lineart
.y1
= 0;
249 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
250 a_focus_indicator
->texture
[3].data
.lineart
.y2
= 0;
251 RrPaint(a_focus_indicator
, focus_indicator
.bottom
.win
,
254 XMapWindow(ob_display
, focus_indicator
.top
.win
);
255 XMapWindow(ob_display
, focus_indicator
.left
.win
);
256 XMapWindow(ob_display
, focus_indicator
.right
.win
);
257 XMapWindow(ob_display
, focus_indicator
.bottom
.win
);