]> Dogcows Code - chaz/openbox/blob - openbox/focus_cycle_indicator.c
move focus_cycle_indicator into its own file
[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
43 static Window create_window(Window parent, gulong mask,
44 XSetWindowAttributes *attrib)
45 {
46 return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
47 RrDepth(ob_rr_inst), InputOutput,
48 RrVisual(ob_rr_inst), mask, attrib);
49
50 }
51
52 void focus_cycle_indicator_startup(gboolean reconfig)
53 {
54 XSetWindowAttributes attr;
55
56 if (reconfig) return;
57
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;
62
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);
77
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));
82
83 color_white = RrColorNew(ob_rr_inst, 0xff, 0xff, 0xff);
84
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,
89 0, 0, 0);
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;
98 }
99
100 void focus_cycle_indicator_shutdown(gboolean reconfig)
101 {
102 if (reconfig) return;
103
104 RrColorFree(color_white);
105
106 RrAppearanceFree(a_focus_indicator);
107
108 XDestroyWindow(ob_display, focus_indicator.top.win);
109 XDestroyWindow(ob_display, focus_indicator.left.win);
110 XDestroyWindow(ob_display, focus_indicator.right.win);
111 XDestroyWindow(ob_display, focus_indicator.bottom.win);
112 }
113
114 void focus_cycle_draw_indicator(ObClient *c)
115 {
116 if (!c) {
117 XUnmapWindow(ob_display, focus_indicator.top.win);
118 XUnmapWindow(ob_display, focus_indicator.left.win);
119 XUnmapWindow(ob_display, focus_indicator.right.win);
120 XUnmapWindow(ob_display, focus_indicator.bottom.win);
121
122 /* kill enter events cause by this unmapping */
123 event_ignore_all_queued_enters();
124 } else {
125 /*
126 if (c)
127 frame_adjust_focus(c->frame, FALSE);
128 frame_adjust_focus(c->frame, TRUE);
129 */
130 gint x, y, w, h;
131 gint wt, wl, wr, wb;
132
133 wt = wl = wr = wb = FOCUS_INDICATOR_WIDTH;
134
135 x = c->frame->area.x;
136 y = c->frame->area.y;
137 w = c->frame->area.width;
138 h = wt;
139
140 XMoveResizeWindow(ob_display, focus_indicator.top.win,
141 x, y, w, h);
142 a_focus_indicator->texture[0].data.lineart.x1 = 0;
143 a_focus_indicator->texture[0].data.lineart.y1 = h-1;
144 a_focus_indicator->texture[0].data.lineart.x2 = 0;
145 a_focus_indicator->texture[0].data.lineart.y2 = 0;
146 a_focus_indicator->texture[1].data.lineart.x1 = 0;
147 a_focus_indicator->texture[1].data.lineart.y1 = 0;
148 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
149 a_focus_indicator->texture[1].data.lineart.y2 = 0;
150 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
151 a_focus_indicator->texture[2].data.lineart.y1 = 0;
152 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
153 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
154 a_focus_indicator->texture[3].data.lineart.x1 = (wl-1);
155 a_focus_indicator->texture[3].data.lineart.y1 = h-1;
156 a_focus_indicator->texture[3].data.lineart.x2 = w - wr;
157 a_focus_indicator->texture[3].data.lineart.y2 = h-1;
158 RrPaint(a_focus_indicator, focus_indicator.top.win,
159 w, h);
160
161 x = c->area.x;
162 y = c->frame->area.y;
163 w = wl;
164 h = c->frame->area.height;
165
166 XMoveResizeWindow(ob_display, focus_indicator.left.win,
167 x, y, w, h);
168 a_focus_indicator->texture[0].data.lineart.x1 = w-1;
169 a_focus_indicator->texture[0].data.lineart.y1 = 0;
170 a_focus_indicator->texture[0].data.lineart.x2 = 0;
171 a_focus_indicator->texture[0].data.lineart.y2 = 0;
172 a_focus_indicator->texture[1].data.lineart.x1 = 0;
173 a_focus_indicator->texture[1].data.lineart.y1 = 0;
174 a_focus_indicator->texture[1].data.lineart.x2 = 0;
175 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
176 a_focus_indicator->texture[2].data.lineart.x1 = 0;
177 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
178 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
179 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
180 a_focus_indicator->texture[3].data.lineart.x1 = w-1;
181 a_focus_indicator->texture[3].data.lineart.y1 = wt-1;
182 a_focus_indicator->texture[3].data.lineart.x2 = w-1;
183 a_focus_indicator->texture[3].data.lineart.y2 = h - wb;
184 RrPaint(a_focus_indicator, focus_indicator.left.win,
185 w, h);
186
187 x = c->frame->area.x + c->frame->area.width - wr;
188 y = c->frame->area.y;
189 w = wr;
190 h = c->frame->area.height ;
191
192 XMoveResizeWindow(ob_display, focus_indicator.right.win,
193 x, y, w, h);
194 a_focus_indicator->texture[0].data.lineart.x1 = 0;
195 a_focus_indicator->texture[0].data.lineart.y1 = 0;
196 a_focus_indicator->texture[0].data.lineart.x2 = w-1;
197 a_focus_indicator->texture[0].data.lineart.y2 = 0;
198 a_focus_indicator->texture[1].data.lineart.x1 = w-1;
199 a_focus_indicator->texture[1].data.lineart.y1 = 0;
200 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
201 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
202 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
203 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
204 a_focus_indicator->texture[2].data.lineart.x2 = 0;
205 a_focus_indicator->texture[2].data.lineart.y2 = h-1;
206 a_focus_indicator->texture[3].data.lineart.x1 = 0;
207 a_focus_indicator->texture[3].data.lineart.y1 = wt-1;
208 a_focus_indicator->texture[3].data.lineart.x2 = 0;
209 a_focus_indicator->texture[3].data.lineart.y2 = h - wb;
210 RrPaint(a_focus_indicator, focus_indicator.right.win,
211 w, h);
212
213 x = c->frame->area.x;
214 y = c->frame->area.y + c->frame->area.height - wb;
215 w = c->frame->area.width;
216 h = wb;
217
218 XMoveResizeWindow(ob_display, focus_indicator.bottom.win,
219 x, y, w, h);
220 a_focus_indicator->texture[0].data.lineart.x1 = 0;
221 a_focus_indicator->texture[0].data.lineart.y1 = 0;
222 a_focus_indicator->texture[0].data.lineart.x2 = 0;
223 a_focus_indicator->texture[0].data.lineart.y2 = h-1;
224 a_focus_indicator->texture[1].data.lineart.x1 = 0;
225 a_focus_indicator->texture[1].data.lineart.y1 = h-1;
226 a_focus_indicator->texture[1].data.lineart.x2 = w-1;
227 a_focus_indicator->texture[1].data.lineart.y2 = h-1;
228 a_focus_indicator->texture[2].data.lineart.x1 = w-1;
229 a_focus_indicator->texture[2].data.lineart.y1 = h-1;
230 a_focus_indicator->texture[2].data.lineart.x2 = w-1;
231 a_focus_indicator->texture[2].data.lineart.y2 = 0;
232 a_focus_indicator->texture[3].data.lineart.x1 = wl-1;
233 a_focus_indicator->texture[3].data.lineart.y1 = 0;
234 a_focus_indicator->texture[3].data.lineart.x2 = w - wr;
235 a_focus_indicator->texture[3].data.lineart.y2 = 0;
236 RrPaint(a_focus_indicator, focus_indicator.bottom.win,
237 w, h);
238
239 XMapWindow(ob_display, focus_indicator.top.win);
240 XMapWindow(ob_display, focus_indicator.left.win);
241 XMapWindow(ob_display, focus_indicator.right.win);
242 XMapWindow(ob_display, focus_indicator.bottom.win);
243 }
244 }
This page took 0.049848 seconds and 5 git commands to generate.