]>
Dogcows Code - chaz/tint2/blob - tint.c
8bf2127c22c714e94d1aebc63565b3e5f8763459
1 /**************************************************************************
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
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 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
29 #include <X11/Xlocale.h>
44 void signal_handler(int sig
)
46 // signal handler is light as it should be
47 panel
.signal_pending
= sig
;
54 signal(SIGUSR1
, signal_handler
);
55 signal(SIGINT
, signal_handler
);
56 signal(SIGTERM
, signal_handler
);
59 memset(&panel
, 0, sizeof(Panel
));
60 memset(&server
, 0, sizeof(Server_global
));
61 memset(&g_task
, 0, sizeof(Global_task
));
62 memset(&g_taskbar
, 0, sizeof(Area
));
63 panel
.clock
.area
.draw_foreground
= draw_foreground_clock
;
64 g_task
.area
.draw_foreground
= draw_foreground_task
;
67 server
.dsp
= XOpenDisplay (NULL
);
69 fprintf(stderr
, "Could not open display.\n");
73 server
.screen
= DefaultScreen (server
.dsp
);
74 server
.root_win
= RootWindow(server
.dsp
, server
.screen
);
75 server
.depth
= DefaultDepth (server
.dsp
, server
.screen
);
76 server
.visual
= DefaultVisual (server
.dsp
, server
.screen
);
77 server
.desktop
= server_get_current_desktop ();
79 XSetErrorHandler ((XErrorHandler
) server_catch_error
);
83 root
= RootWindow(display
, DefaultScreen(display
));
84 //create_main_window();
89 imlib_context_set_display (server
.dsp
);
90 imlib_context_set_visual (server
.visual
);
91 imlib_context_set_colormap (DefaultColormap (server
.dsp
, server
.screen
));
94 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
96 setlocale (LC_ALL
, "");
100 void window_action (Task
*tsk
, int action
)
104 set_close (tsk
->win
);
107 set_active(tsk
->win
);
110 XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
113 if (tsk
== panel
.task_active
) XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
114 else set_active (tsk
->win
);
117 window_toggle_shade (tsk
->win
);
123 void event_button_press (int x
, int y
)
125 if (panel
.mode
== SINGLE_DESKTOP
) {
126 // drag and drop disabled
127 XLowerWindow (server
.dsp
, window
.main_win
);
133 for (l0
= panel
.area
.list
; l0
; l0
= l0
->next
) {
135 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
141 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
143 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
144 panel
.task_drag
= tsk
;
150 XLowerWindow (server
.dsp
, window
.main_win
);
154 void event_button_release (int button
, int x
, int y
)
156 int action
= TOGGLE_ICONIFY
;
157 // TODO: convert event_button_press(int x, int y) to area->event_button_press()
162 action
= panel
.mouse_middle
;
165 action
= panel
.mouse_right
;
168 action
= panel
.mouse_scroll_up
;
171 action
= panel
.mouse_scroll_down
;
178 for (l0
= panel
.area
.list
; l0
; l0
= l0
->next
) {
180 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
184 // TODO: check better solution to keep window below
185 XLowerWindow (server
.dsp
, window
.main_win
);
190 // drag and drop task
191 if (panel
.task_drag
) {
192 if (tskbar
!= panel
.task_drag
->area
.parent
&& action
== TOGGLE_ICONIFY
) {
193 windows_set_desktop(panel
.task_drag
->win
, tskbar
->desktop
);
194 if (tskbar
->desktop
== server
.desktop
)
195 set_active(panel
.task_drag
->win
);
199 else panel
.task_drag
= 0;
203 if (panel
.mode
== MULTI_DESKTOP
)
204 if (tskbar
->desktop
!= server
.desktop
&& action
!= CLOSE
)
205 set_desktop (tskbar
->desktop
);
210 for (l
= tskbar
->area
.list
; l
; l
= l
->next
) {
212 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
213 window_action (tsk
, action
);
218 // to keep window below
219 XLowerWindow (server
.dsp
, window
.main_win
);
223 void event_property_notify (Window win
, Atom at
)
226 if (win
== server
.root_win
) {
227 if (!server
.got_root_win
) {
228 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
229 server
.got_root_win
= 1;
232 /* Change number of desktops */
233 else if (at
== server
.atom
._NET_NUMBER_OF_DESKTOPS
) {
238 else if (at
== server
.atom
._NET_CURRENT_DESKTOP
) {
239 server
.desktop
= server_get_current_desktop ();
240 if (panel
.mode
!= MULTI_DESKTOP
) {
245 else if (at
== server
.atom
._NET_CLIENT_LIST
) {
246 task_refresh_tasklist ();
250 else if (at
== server
.atom
._NET_ACTIVE_WINDOW
) {
251 Window w1
= window_get_active ();
252 Task
*t
= task_get_task(w1
);
253 if (t
) panel
.task_active
= t
;
256 if (XGetTransientForHint(server
.dsp
, w1
, &w2
) != 0)
257 if (w2
) panel
.task_active
= task_get_task(w2
);
261 /* Wallpaper changed */
262 else if (at
== server
.atom
._XROOTPMAP_ID
) {
263 XFreePixmap (server
.dsp
, panel
.area
.pmap
);
270 tsk
= task_get_task (win
);
272 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
274 /* Window title changed */
275 if (at
== server
.atom
._NET_WM_VISIBLE_NAME
|| at
== server
.atom
._NET_WM_NAME
|| at
== server
.atom
.WM_NAME
) {
277 tsk
->area
.redraw
= 1;
281 else if (at
== server
.atom
.WM_STATE
) {
282 if (window_is_iconified (win
))
283 if (panel
.task_active
== tsk
) panel
.task_active
= 0;
285 /* Window icon changed */
286 else if (at
== server
.atom
._NET_WM_ICON
) {
287 if (tsk
->icon_data
) {
288 free (tsk
->icon_data
);
291 tsk
->area
.redraw
= 1;
294 /* Window desktop changed */
295 else if (at
== server
.atom
._NET_WM_DESKTOP
) {
301 if (!server
.got_root_win
) server
.root_win
= RootWindow (server
.dsp
, server
.screen
);
306 void event_configure_notify (Window win
)
310 tsk
= task_get_task (win
);
313 Taskbar
*tskbar
= tsk
->area
.parent
;
314 if (tskbar
->monitor
!= window_get_monitor (win
)) {
315 // task on another monitor
327 if (!panel
.clock
.time1_format
) return;
329 if (gettimeofday(&stv
, 0)) return;
331 if (abs(stv
.tv_sec
- panel
.clock
.clock
.tv_sec
) < panel
.clock
.time_precision
) return;
334 panel
.clock
.clock
.tv_sec
= stv
.tv_sec
;
335 panel
.clock
.clock
.tv_sec
-= panel
.clock
.clock
.tv_sec
% panel
.clock
.time_precision
;
336 panel
.clock
.area
.redraw
= 1;
341 int main (int argc
, char *argv
[])
348 c
= getopt (argc
, argv
, "c:");
352 if (panel
.area
.pmap
) XFreePixmap (server
.dsp
, panel
.area
.pmap
);
354 // append full transparency background
355 list_back
= g_slist_append(0, calloc(1, sizeof(Area
)));
357 // read tint2rc config
360 i
= config_read_file (optarg
);
364 fprintf(stderr
, "usage: tint2 [-c] <config_file>\n");
370 window_draw_panel ();
372 // BUG: refresh(clock) is needed here, but 'on the paper' it's not necessary.
373 refresh(&panel
.clock
.area
);
375 x11_fd
= ConnectionNumber (server
.dsp
);
376 XSync (server
.dsp
, False
);
379 // thanks to AngryLlama for the timer
380 // Create a File Description Set containing x11_fd
382 FD_SET (x11_fd
, &fd
);
387 // Wait for X Event or a Timer
388 if (select(x11_fd
+1, &fd
, 0, 0, &tv
)) {
389 while (XPending (server
.dsp
)) {
390 XNextEvent(server
.dsp
, &e
);
394 if (e
.xbutton
.button
== 1) event_button_press (e
.xbutton
.x
, e
.xbutton
.y
);
398 event_button_release (e
.xbutton
.button
, e
.xbutton
.x
, e
.xbutton
.y
);
402 XCopyArea (server
.dsp
, panel
.area
.pmap
, server
.root_win
, server
.gc_root
, 0, 0, panel
.area
.width
, panel
.area
.height
, server
.posx
, server
.posy
);
403 XCopyArea (server
.dsp
, server
.pmap
, window
.main_win
, server
.gc
, panel
.area
.paddingx
, 0, panel
.area
.width
-(2*panel
.area
.paddingx
), panel
.area
.height
, 0, 0);
407 //printf("PropertyNotify\n");
408 event_property_notify (e
.xproperty
.window
, e
.xproperty
.atom
);
411 case ConfigureNotify
:
412 if (e
.xconfigure
.window
== server
.root_win
)
415 if (panel
.mode
== MULTI_MONITOR
)
416 event_configure_notify (e
.xconfigure
.window
);
423 switch (panel
.signal_pending
) {
432 if (panel
.refresh
&& !panel
.sleep_mode
) {
434 //printf(" *** visual_refresh\n");
This page took 0.048254 seconds and 3 git commands to generate.