]>
Dogcows Code - chaz/tint2/blob - src/tint.c
10ccb3638672d9b366994d9907cb726bb4ce71a8
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
54 signal(SIGUSR1
, signal_handler
);
55 signal(SIGINT
, signal_handler
);
56 signal(SIGTERM
, signal_handler
);
59 memset(&server
, 0, sizeof(Server_global
));
61 server
.dsp
= XOpenDisplay (NULL
);
63 fprintf(stderr
, "Could not open display.\n");
67 server
.screen
= DefaultScreen (server
.dsp
);
68 server
.root_win
= RootWindow(server
.dsp
, server
.screen
);
69 server
.depth
= DefaultDepth (server
.dsp
, server
.screen
);
70 server
.visual
= DefaultVisual (server
.dsp
, server
.screen
);
71 server
.desktop
= server_get_current_desktop ();
73 server
.gc
= XCreateGC (server
.dsp
, server
.root_win
, (unsigned long)0, &gcv
) ;
75 XSetErrorHandler ((XErrorHandler
) server_catch_error
);
78 //display = server.dsp;
79 //root = RootWindow(display, DefaultScreen(display));
80 //create_main_window();
85 imlib_context_set_display (server
.dsp
);
86 imlib_context_set_visual (server
.visual
);
87 imlib_context_set_colormap (DefaultColormap (server
.dsp
, server
.screen
));
90 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
92 setlocale (LC_ALL
, "");
100 if (time1_font_desc
) pango_font_description_free(time1_font_desc
);
101 if (time2_font_desc
) pango_font_description_free(time2_font_desc
);
102 if (time1_format
) g_free(time1_format
);
103 if (time2_format
) g_free(time2_format
);
105 if (server
.monitor
) free(server
.monitor
);
106 XFreeGC(server
.dsp
, server
.gc
);
107 XCloseDisplay(server
.dsp
);
111 void window_action (Task
*tsk
, int action
)
115 set_close (tsk
->win
);
118 set_active(tsk
->win
);
121 XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
124 if (tsk
== task_active
) XIconifyWindow (server
.dsp
, tsk
->win
, server
.screen
);
125 else set_active (tsk
->win
);
128 window_toggle_shade (tsk
->win
);
134 void event_button_press (XEvent
*e
)
136 Panel
*panel
= get_panel(e
->xany
.window
);
139 if (panel_mode
!= MULTI_DESKTOP
) {
140 // drag and drop disabled
141 //XLowerWindow (server.dsp, panel.main_win);
147 int x
= e
->xbutton
.x
;
148 int y
= e
->xbutton
.y
;
149 for (l0
= panel
->area
.list
; l0
; l0
= l0
->next
) {
151 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
157 for (l0
= tskbar
->area
.list
; l0
; l0
= l0
->next
) {
159 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
166 //XLowerWindow (server.dsp, panel.main_win);
170 void event_button_release (XEvent
*e
)
172 // TODO: convert event_button_press(int x, int y) to area->event_button_press()
174 Panel
*panel
= get_panel(e
->xany
.window
);
177 int action
= TOGGLE_ICONIFY
;
178 int x
= e
->xbutton
.x
;
179 int y
= e
->xbutton
.y
;
180 switch (e
->xbutton
.button
) {
182 action
= mouse_middle
;
185 action
= mouse_right
;
188 action
= mouse_scroll_up
;
191 action
= mouse_scroll_down
;
198 for (l0
= panel
->area
.list
; l0
; l0
= l0
->next
) {
200 if (x
>= tskbar
->area
.posx
&& x
<= (tskbar
->area
.posx
+ tskbar
->area
.width
))
204 // TODO: check better solution to keep window below
205 //XLowerWindow (server.dsp, panel.main_win);
210 // drag and drop task
212 if (tskbar
!= task_drag
->area
.parent
&& action
== TOGGLE_ICONIFY
) {
213 if (task_drag
->desktop
!= ALLDESKTOP
&& panel_mode
== MULTI_DESKTOP
) {
214 windows_set_desktop(task_drag
->win
, tskbar
->desktop
);
215 if (tskbar
->desktop
== server
.desktop
)
216 set_active(task_drag
->win
);
225 if (panel_mode
== MULTI_DESKTOP
)
226 if (tskbar
->desktop
!= server
.desktop
&& action
!= CLOSE
)
227 set_desktop (tskbar
->desktop
);
232 for (l
= tskbar
->area
.list
; l
; l
= l
->next
) {
234 if (x
>= tsk
->area
.posx
&& x
<= (tsk
->area
.posx
+ tsk
->area
.width
)) {
235 window_action (tsk
, action
);
240 // to keep window below
241 //XLowerWindow (server.dsp, panel.main_win);
245 void event_property_notify (Window win
, Atom at
)
250 if (win
== server
.root_win
) {
251 if (!server
.got_root_win
) {
252 XSelectInput (server
.dsp
, server
.root_win
, PropertyChangeMask
|StructureNotifyMask
);
253 server
.got_root_win
= 1;
256 /* Change number of desktops */
257 else if (at
== server
.atom
._NET_NUMBER_OF_DESKTOPS
) {
258 server
.nb_desktop
= server_get_number_of_desktop ();
262 task_refresh_tasklist();
266 else if (at
== server
.atom
._NET_CURRENT_DESKTOP
) {
267 server
.desktop
= server_get_current_desktop ();
268 if (panel_mode
!= MULTI_DESKTOP
) {
273 else if (at
== server
.atom
._NET_CLIENT_LIST
) {
274 task_refresh_tasklist();
278 else if (at
== server
.atom
._NET_ACTIVE_WINDOW
) {
281 for (i
=0 ; i
< nb_panel
; i
++) {
282 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
283 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
285 tsk
->area
.is_active
= 0;
291 Window w1
= window_get_active ();
292 Task
*t
= task_get_task(w1
);
295 if (XGetTransientForHint(server
.dsp
, w1
, &w2
) != 0)
296 if (w2
) t
= task_get_task(w2
);
299 for (i
=0 ; i
< nb_panel
; i
++) {
300 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
301 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
303 if (tsk
->win
== t
->win
) {
304 tsk
->area
.is_active
= 1;
305 //printf("active monitor %d, task %s\n", panel1[i].monitor, tsk->title);
314 /* Wallpaper changed */
315 else if (at
== server
.atom
._XROOTPMAP_ID
) {
316 for (i
=0 ; i
< nb_panel
; i
++) {
317 set_panel_background(&panel1
[i
]);
323 tsk
= task_get_task (win
);
325 //printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
327 /* Window title changed */
328 if (at
== server
.atom
._NET_WM_VISIBLE_NAME
|| at
== server
.atom
._NET_WM_NAME
|| at
== server
.atom
.WM_NAME
) {
332 // changed other tsk->title
333 for (i
=0 ; i
< nb_panel
; i
++) {
334 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
335 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
337 if (tsk
->win
== tsk2
->win
&& tsk
!= tsk2
) {
338 tsk2
->title
= tsk
->title
;
339 tsk2
->area
.redraw
= 1;
347 else if (at
== server
.atom
.WM_STATE
) {
348 if (window_is_iconified (win
))
350 if (task_active
->win
== tsk
->win
) {
353 for (i
=0 ; i
< nb_panel
; i
++) {
354 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
355 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
357 tsk2
->area
.is_active
= 0;
365 /* Window icon changed */
366 else if (at
== server
.atom
._NET_WM_ICON
) {
370 for (i
=0 ; i
< nb_panel
; i
++) {
371 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
372 for (l0
= panel1
[i
].taskbar
[j
].area
.list
; l0
; l0
= l0
->next
) {
374 if (tsk
->win
== tsk2
->win
&& tsk
!= tsk2
) {
375 tsk2
->icon_width
= tsk
->icon_width
;
376 tsk2
->icon_height
= tsk
->icon_height
;
377 tsk2
->icon_data
= tsk
->icon_data
;
378 tsk2
->area
.redraw
= 1;
385 /* Window desktop changed */
386 else if (at
== server
.atom
._NET_WM_DESKTOP
) {
392 if (!server
.got_root_win
) server
.root_win
= RootWindow (server
.dsp
, server
.screen
);
397 void event_configure_notify (Window win
)
399 if (panel_mode
!= SINGLE_MONITOR
) return;
400 if (server
.nb_monitor
== 1) return;
402 Task
*tsk
= task_get_task (win
);
405 Panel
*p
= tsk
->area
.panel
;
406 if (p
->monitor
!= window_get_monitor (win
)) {
407 // task on another monitor
419 if (!time1_format
) return;
421 if (gettimeofday(&stv
, 0)) return;
423 if (abs(stv
.tv_sec
- time_clock
.tv_sec
) < time_precision
) return;
426 time_clock
.tv_sec
= stv
.tv_sec
;
427 time_clock
.tv_sec
-= time_clock
.tv_sec
% time_precision
;
430 for (i
=0 ; i
< nb_panel
; i
++) {
431 panel1
[i
].clock
.area
.redraw
= 1;
437 int main (int argc
, char *argv
[])
445 c
= getopt (argc
, argv
, "c:");
452 i
= config_read_file (optarg
);
456 fprintf(stderr
, "usage: tint2 [-c] <config_file>\n");
462 // BUG: refresh(clock) is needed here, but 'on the paper' it's not necessary.
463 for (i
=0 ; i
< nb_panel
; i
++) {
464 refresh(&panel1
[i
].clock
.area
);
467 x11_fd
= ConnectionNumber(server
.dsp
);
468 XSync(server
.dsp
, False
);
471 // thanks to AngryLlama for the timer
472 // Create a File Description Set containing x11_fd
474 FD_SET (x11_fd
, &fd
);
479 // Wait for X Event or a Timer
480 if (select(x11_fd
+1, &fd
, 0, 0, &tv
)) {
481 while (XPending (server
.dsp
)) {
482 XNextEvent(server
.dsp
, &e
);
486 //printf("ButtonPress %lx\n", e.xproperty.window);
487 if (e
.xbutton
.button
== 1) event_button_press (&e
);
491 event_button_release (&e
);
495 panel
= get_panel(e
.xany
.window
);
497 //XCopyArea (server.dsp, panel.area.pix.pmap, server.root_win, server.gc_root, 0, 0, panel.area.width, panel.area.height, server.posx, server.posy);
498 //XCopyArea (server.dsp, server.pmap, panel.main_win, server.gc, panel.area.paddingxlr, 0, panel.area.width-(2*panel.area.paddingxlr), panel.area.height, 0, 0);
499 XCopyArea (server
.dsp
, panel
->root_pmap
, panel
->main_win
, server
.gc
, 0, 0, panel
->area
.width
, panel
->area
.height
, 0, 0);
503 //printf("PropertyNotify %lx\n", e.xproperty.window);
504 event_property_notify (e
.xproperty
.window
, e
.xproperty
.atom
);
507 case ConfigureNotify
:
508 if (e
.xconfigure
.window
== server
.root_win
)
511 event_configure_notify (e
.xconfigure
.window
);
518 switch (signal_pending
) {
528 for (i
=0 ; i
< nb_panel
; i
++)
529 visual_refresh(&panel1
[i
]);
This page took 0.05644 seconds and 4 git commands to generate.