#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xlocale.h>
+#include <X11/extensions/Xdamage.h>
#include <Imlib2.h>
#include <signal.h>
printf("tint2 version 0.8\n");
exit(0);
}
- if (!strcmp(argv[i], "-c")) {
+ if (!strcmp(argv[i], "-c")) {
i++;
if (i < argc)
config_path = strdup(argv[i]);
snapshot_path = strdup(argv[i]);
}
}
-
// Set signal handler
struct sigaction sa = { .sa_handler = signal_handler };
sigaction(SIGUSR1, &sa, 0);
sigaction(SIGTERM, &sa, 0);
sigaction(SIGHUP, &sa, 0);
signal(SIGCHLD, SIG_IGN); // don't have to wait() after fork()
- // block all signals, such that no race conditions occur before pselect in our main loop
- sigset_t block_mask;
- sigaddset(&block_mask, SIGINT);
- sigaddset(&block_mask, SIGTERM);
- sigaddset(&block_mask, SIGHUP);
- sigaddset(&block_mask, SIGUSR1);
- sigprocmask(SIG_BLOCK, &block_mask, 0);
+ // BSD is too stupid to support pselect(), therefore we have to use select and hope that we do not
+ // end up in a race condition there
+ // block all signals, such that no race conditions occur before pselect in our main loop
+// sigset_t block_mask;
+// sigaddset(&block_mask, SIGINT);
+// sigaddset(&block_mask, SIGTERM);
+// sigaddset(&block_mask, SIGHUP);
+// sigaddset(&block_mask, SIGUSR1);
+// sigprocmask(SIG_BLOCK, &block_mask, 0);
// set global data
memset(&server, 0, sizeof(Server_global));
memset(&systray, 0, sizeof(Systraybar));
+}
+void init_X11()
+{
server.dsp = XOpenDisplay (NULL);
if (!server.dsp) {
fprintf(stderr, "tint2 exit : could not open display.\n");
gchar *path;
const gchar * const *data_dirs;
data_dirs = g_get_system_data_dirs ();
+ int i;
for (i = 0; data_dirs[i] != NULL; i++) {
path = g_build_filename(data_dirs[i], "tint2", "default_icon.png", NULL);
if (g_file_test (path, G_FILE_TEST_EXISTS))
void cleanup()
{
+ stop_all_timeouts();
cleanup_systray();
stop_net();
cleanup_panel();
if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) {
forward_click(e);
+ XLowerWindow (server.dsp, panel->main_win);
task_drag = 0;
return;
}
void event_property_notify (XEvent *e)
{
- int i, j;
+ int i;
Task *tsk;
Window win = e->xproperty.window;
Atom at = e->xproperty.atom;
// redraw both taskbar
if (server.nb_desktop > old_desktop) {
// can happen if last desktop is deleted and we've been on the last desktop
- panel->taskbar[old_desktop].area.is_active = 0;
+ panel->taskbar[old_desktop].area.bg = panel->g_taskbar.bg;
panel->taskbar[old_desktop].area.resize = 1;
}
- panel->taskbar[server.desktop].area.is_active = 1;
+ panel->taskbar[server.desktop].area.bg = panel->g_taskbar.bg_active;
panel->taskbar[server.desktop].area.resize = 1;
panel_refresh = 1;
}
// Window title changed
if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
- Task *tsk2;
- GSList *l0;
get_title(tsk);
- // changed other tsk->title
- for (i=0 ; i < nb_panel ; i++) {
- for (j=0 ; j < panel1[i].nb_desktop ; j++) {
- for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
- tsk2 = l0->data;
- if (tsk->win == tsk2->win && tsk != tsk2) {
- tsk2->title = tsk->title;
- tsk2->area.redraw = 1;
- }
- }
- }
- }
panel_refresh = 1;
}
// Demand attention
panel_refresh = 1;
}
}
-// We do not check for the iconified state, since it only unsets our active window
-// but in openbox a shaded window is considered iconified. So we would loose the active window
-// property on unshading it again (commented 01.10.2009)
-// else if (at == server.atom.WM_STATE) {
-// // Iconic state
-// // TODO : try to delete following code
-// if (window_is_iconified (win)) {
-// if (task_active) {
-// if (task_active->win == tsk->win) {
-// Task *tsk2;
-// GSList *l0;
-// for (i=0 ; i < nb_panel ; i++) {
-// for (j=0 ; j < panel1[i].nb_desktop ; j++) {
-// for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
-// tsk2 = l0->data;
-// tsk2->area.is_active = 0;
-// }
-// }
-// }
-// task_active = 0;
-// }
-// }
-// }
-// }
+ else if (at == server.atom.WM_STATE) {
+ // Iconic state
+ int state = (task_active && tsk->win == task_active->win ? TASK_ACTIVE : TASK_NORMAL);
+ if (window_is_iconified(win))
+ state = TASK_ICONIFIED;
+ set_task_state(tsk, state);
+ panel_refresh = 1;
+ }
// Window icon changed
else if (at == server.atom._NET_WM_ICON) {
get_icon(tsk);
- Task *tsk2;
- GSList *l0;
- for (i=0 ; i < nb_panel ; i++) {
- for (j=0 ; j < panel1[i].nb_desktop ; j++) {
- for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
- tsk2 = l0->data;
- if (tsk->win == tsk2->win && tsk != tsk2) {
- tsk2->icon_width = tsk->icon_width;
- tsk2->icon_height = tsk->icon_height;
- tsk2->icon = tsk->icon;
- tsk2->icon_active = tsk->icon_active;
- tsk2->area.redraw = 1;
- }
- }
- }
- }
panel_refresh = 1;
}
// Window desktop changed
GSList *l;
for (l = systray.list_icons; l ; l = l->next) {
traywin = (TrayWindow*)l->data;
- if (traywin->id == win) {
+ if (traywin->tray_id == win) {
//printf("move tray %d\n", traywin->x);
XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
+ XResizeWindow(server.dsp, traywin->tray_id, traywin->width, traywin->height);
panel_refresh = 1;
return;
}
Panel *p = tsk->area.panel;
if (p->monitor != window_get_monitor (win)) {
remove_task (tsk);
- add_task (win);
+ tsk = add_task (win);
if (win == window_get_active ()) {
- GSList* task_list = task_get_tasks(win);
- while (task_list) {
- Task *tsk = task_list->data;
- tsk->area.is_active = 1;
- task_active = tsk;
- task_list = task_list->next;
- }
+ set_task_state(tsk, TASK_ACTIVE);
+ task_active = tsk;
}
panel_refresh = 1;
}
int x11_fd, i;
Panel *panel;
GSList *it;
- const struct timespec* timeout;
+ struct timeval* timeout;
init (argc, argv);
-
- i = 0;
init_config();
+ i = 0;
if (config_path)
i = config_read_file (config_path);
else
cleanup();
exit(1);
}
+
+ init_X11();
init_panel();
cleanup_config();
if (snapshot_path) {
exit(0);
}
+ int damage_event, damage_error;
+ XDamageQueryExtension(server.dsp, &damage_event, &damage_error);
x11_fd = ConnectionNumber(server.dsp);
XSync(server.dsp, False);
- sigset_t empty_mask;
- sigemptyset(&empty_mask);
+// sigset_t empty_mask;
+// sigemptyset(&empty_mask);
while (1) {
if (panel_refresh) {
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
- if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
- panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
-
- refresh(&panel->area);
- XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+ if (panel->is_hidden)
+ XCopyArea(server.dsp, panel->hidden_pixmap, panel->main_win, server.gc, 0, 0, panel->hidden_width, panel->hidden_height, 0, 0);
+ else {
+ if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
+ panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
+ refresh(&panel->area);
+ XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+ }
}
XFlush (server.dsp);
- if (refresh_systray) {
+ panel = (Panel*)systray.area.panel;
+ if (refresh_systray && !panel->is_hidden) {
refresh_systray = 0;
panel = (Panel*)systray.area.panel;
// tint2 doen't draw systray icons. it just redraw background.
FD_ZERO (&fdset);
FD_SET (x11_fd, &fdset);
update_next_timeout();
- if (next_timeout.tv_sec >= 0 && next_timeout.tv_nsec >= 0)
+ if (next_timeout.tv_sec >= 0 && next_timeout.tv_usec >= 0)
timeout = &next_timeout;
else
timeout = 0;
// Wait for X Event or a Timer
- if (pselect(x11_fd+1, &fdset, 0, 0, timeout, &empty_mask) > 0) {
+ if (select(x11_fd+1, &fdset, 0, 0, timeout) > 0) {
while (XPending (server.dsp)) {
XNextEvent(server.dsp, &e);
+ panel = get_panel(e.xany.window);
+ if (panel && panel_autohide) {
+ if (e.type == EnterNotify)
+ autohide_trigger_show(panel);
+ else if (e.type == LeaveNotify)
+ autohide_trigger_hide(panel);
+ if (panel->is_hidden)
+ continue; // discard further processing of this event because the panel is not visible yet
+ }
+
switch (e.type) {
case ButtonPress:
- tooltip_hide();
+ tooltip_hide(0);
event_button_press (&e);
break;
}
case LeaveNotify:
- tooltip_trigger_hide();
+ if (g_tooltip.enabled)
+ tooltip_trigger_hide();
break;
case Expose:
if (e.xany.window == g_tooltip.window || !systray.area.on_screen)
break;
for (it = systray.list_icons; it; it = g_slist_next(it)) {
- if (((TrayWindow*)it->data)->id == e.xany.window) {
+ if (((TrayWindow*)it->data)->tray_id == e.xany.window) {
remove_icon((TrayWindow*)it->data);
break;
}
dnd_message(&e.xclient);
}
break;
+
+ default:
+ if (e.type == XDamageNotify+damage_event) {
+ TrayWindow *traywin;
+ GSList *l;
+ XDamageNotifyEvent* de = (XDamageNotifyEvent*)&e;
+ for (l = systray.list_icons; l ; l = l->next) {
+ traywin = (TrayWindow*)l->data;
+ if ( traywin->id == de->drawable && !de->more ) {
+ systray_render_icon(traywin);
+ break;
+ }
+ }
+ }
}
}
}