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
;
43 static Window
create_window(Window parent
, gulong mask
,
44 XSetWindowAttributes
*attrib
)
46 return XCreateWindow(ob_display
, parent
, 0, 0, 1, 1, 0,
47 RrDepth(ob_rr_inst
), InputOutput
,
48 RrVisual(ob_rr_inst
), mask
, attrib
);
52 void focus_cycle_indicator_startup(gboolean reconfig
)
54 XSetWindowAttributes attr
;
58 focus_indicator
.top
.obwin
.type
= Window_Internal
;
59 focus_indicator
.left
.obwin
.type
= Window_Internal
;
60 focus_indicator
.right
.obwin
.type
= Window_Internal
;
61 focus_indicator
.bottom
.obwin
.type
= Window_Internal
;
63 attr
.override_redirect
= True
;
64 attr
.background_pixel
= BlackPixel(ob_display
, ob_screen
);
65 focus_indicator
.top
.win
=
66 create_window(RootWindow(ob_display
, ob_screen
),
67 CWOverrideRedirect
| CWBackPixel
, &attr
);
68 focus_indicator
.left
.win
=
69 create_window(RootWindow(ob_display
, ob_screen
),
70 CWOverrideRedirect
| CWBackPixel
, &attr
);
71 focus_indicator
.right
.win
=
72 create_window(RootWindow(ob_display
, ob_screen
),
73 CWOverrideRedirect
| CWBackPixel
, &attr
);
74 focus_indicator
.bottom
.win
=
75 create_window(RootWindow(ob_display
, ob_screen
),
76 CWOverrideRedirect
| CWBackPixel
, &attr
);
78 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.top
));
79 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.left
));
80 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.right
));
81 stacking_add(INTERNAL_AS_WINDOW(&focus_indicator
.bottom
));
83 color_white
= RrColorNew(ob_rr_inst
, 0xff, 0xff, 0xff);
85 a_focus_indicator
= RrAppearanceNew(ob_rr_inst
, 4);
86 a_focus_indicator
->surface
.grad
= RR_SURFACE_SOLID
;
87 a_focus_indicator
->surface
.relief
= RR_RELIEF_FLAT
;
88 a_focus_indicator
->surface
.primary
= RrColorNew(ob_rr_inst
,
90 a_focus_indicator
->texture
[0].type
= RR_TEXTURE_LINE_ART
;
91 a_focus_indicator
->texture
[0].data
.lineart
.color
= color_white
;
92 a_focus_indicator
->texture
[1].type
= RR_TEXTURE_LINE_ART
;
93 a_focus_indicator
->texture
[1].data
.lineart
.color
= color_white
;
94 a_focus_indicator
->texture
[2].type
= RR_TEXTURE_LINE_ART
;
95 a_focus_indicator
->texture
[2].data
.lineart
.color
= color_white
;
96 a_focus_indicator
->texture
[3].type
= RR_TEXTURE_LINE_ART
;
97 a_focus_indicator
->texture
[3].data
.lineart
.color
= color_white
;
100 void focus_cycle_indicator_shutdown(gboolean reconfig
)
102 if (reconfig
) return;
104 RrColorFree(color_white
);
106 RrAppearanceFree(a_focus_indicator
);
108 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.top
));
109 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.left
));
110 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.right
));
111 stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator
.bottom
));
113 XDestroyWindow(ob_display
, focus_indicator
.top
.win
);
114 XDestroyWindow(ob_display
, focus_indicator
.left
.win
);
115 XDestroyWindow(ob_display
, focus_indicator
.right
.win
);
116 XDestroyWindow(ob_display
, focus_indicator
.bottom
.win
);
119 void focus_cycle_draw_indicator(ObClient
*c
)
124 /* kill enter events cause by this unmapping */
125 ignore_start
= event_start_ignore_all_enters();
127 XUnmapWindow(ob_display
, focus_indicator
.top
.win
);
128 XUnmapWindow(ob_display
, focus_indicator
.left
.win
);
129 XUnmapWindow(ob_display
, focus_indicator
.right
.win
);
130 XUnmapWindow(ob_display
, focus_indicator
.bottom
.win
);
132 event_end_ignore_all_enters(ignore_start
);
136 frame_adjust_focus(c->frame, FALSE);
137 frame_adjust_focus(c->frame, TRUE);
142 wt
= wl
= wr
= wb
= FOCUS_INDICATOR_WIDTH
;
144 x
= c
->frame
->area
.x
;
145 y
= c
->frame
->area
.y
;
146 w
= c
->frame
->area
.width
;
149 XMoveResizeWindow(ob_display
, focus_indicator
.top
.win
,
151 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
152 a_focus_indicator
->texture
[0].data
.lineart
.y1
= h
-1;
153 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
154 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
155 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
156 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
157 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
158 a_focus_indicator
->texture
[1].data
.lineart
.y2
= 0;
159 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
160 a_focus_indicator
->texture
[2].data
.lineart
.y1
= 0;
161 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
162 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
163 a_focus_indicator
->texture
[3].data
.lineart
.x1
= (wl
-1);
164 a_focus_indicator
->texture
[3].data
.lineart
.y1
= h
-1;
165 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
166 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
-1;
167 RrPaint(a_focus_indicator
, focus_indicator
.top
.win
,
170 x
= c
->frame
->area
.x
;
171 y
= c
->frame
->area
.y
;
173 h
= c
->frame
->area
.height
;
175 XMoveResizeWindow(ob_display
, focus_indicator
.left
.win
,
177 a_focus_indicator
->texture
[0].data
.lineart
.x1
= w
-1;
178 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
179 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
180 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
181 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
182 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
183 a_focus_indicator
->texture
[1].data
.lineart
.x2
= 0;
184 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
185 a_focus_indicator
->texture
[2].data
.lineart
.x1
= 0;
186 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
187 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
188 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
189 a_focus_indicator
->texture
[3].data
.lineart
.x1
= w
-1;
190 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
191 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
-1;
192 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
193 RrPaint(a_focus_indicator
, focus_indicator
.left
.win
,
196 x
= c
->frame
->area
.x
+ c
->frame
->area
.width
- wr
;
197 y
= c
->frame
->area
.y
;
199 h
= c
->frame
->area
.height
;
201 XMoveResizeWindow(ob_display
, focus_indicator
.right
.win
,
203 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
204 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
205 a_focus_indicator
->texture
[0].data
.lineart
.x2
= w
-1;
206 a_focus_indicator
->texture
[0].data
.lineart
.y2
= 0;
207 a_focus_indicator
->texture
[1].data
.lineart
.x1
= w
-1;
208 a_focus_indicator
->texture
[1].data
.lineart
.y1
= 0;
209 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
210 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
211 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
212 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
213 a_focus_indicator
->texture
[2].data
.lineart
.x2
= 0;
214 a_focus_indicator
->texture
[2].data
.lineart
.y2
= h
-1;
215 a_focus_indicator
->texture
[3].data
.lineart
.x1
= 0;
216 a_focus_indicator
->texture
[3].data
.lineart
.y1
= wt
-1;
217 a_focus_indicator
->texture
[3].data
.lineart
.x2
= 0;
218 a_focus_indicator
->texture
[3].data
.lineart
.y2
= h
- wb
;
219 RrPaint(a_focus_indicator
, focus_indicator
.right
.win
,
222 x
= c
->frame
->area
.x
;
223 y
= c
->frame
->area
.y
+ c
->frame
->area
.height
- wb
;
224 w
= c
->frame
->area
.width
;
227 XMoveResizeWindow(ob_display
, focus_indicator
.bottom
.win
,
229 a_focus_indicator
->texture
[0].data
.lineart
.x1
= 0;
230 a_focus_indicator
->texture
[0].data
.lineart
.y1
= 0;
231 a_focus_indicator
->texture
[0].data
.lineart
.x2
= 0;
232 a_focus_indicator
->texture
[0].data
.lineart
.y2
= h
-1;
233 a_focus_indicator
->texture
[1].data
.lineart
.x1
= 0;
234 a_focus_indicator
->texture
[1].data
.lineart
.y1
= h
-1;
235 a_focus_indicator
->texture
[1].data
.lineart
.x2
= w
-1;
236 a_focus_indicator
->texture
[1].data
.lineart
.y2
= h
-1;
237 a_focus_indicator
->texture
[2].data
.lineart
.x1
= w
-1;
238 a_focus_indicator
->texture
[2].data
.lineart
.y1
= h
-1;
239 a_focus_indicator
->texture
[2].data
.lineart
.x2
= w
-1;
240 a_focus_indicator
->texture
[2].data
.lineart
.y2
= 0;
241 a_focus_indicator
->texture
[3].data
.lineart
.x1
= wl
-1;
242 a_focus_indicator
->texture
[3].data
.lineart
.y1
= 0;
243 a_focus_indicator
->texture
[3].data
.lineart
.x2
= w
- wr
;
244 a_focus_indicator
->texture
[3].data
.lineart
.y2
= 0;
245 RrPaint(a_focus_indicator
, focus_indicator
.bottom
.win
,
248 XMapWindow(ob_display
, focus_indicator
.top
.win
);
249 XMapWindow(ob_display
, focus_indicator
.left
.win
);
250 XMapWindow(ob_display
, focus_indicator
.right
.win
);
251 XMapWindow(ob_display
, focus_indicator
.bottom
.win
);