X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Ftint.c;h=cdb72a88cfa70751b525e927e21895c6aec783a1;hb=8622308774bcb0569c8ffa1ea3f928b9d20f35b8;hp=3be5311d1b67599e686c9fc02a633ddabed94571;hpb=3e1153b962ca36936552b6509ac84a5e83ae4873;p=chaz%2Ftint2 diff --git a/src/tint.c b/src/tint.c index 3be5311..cdb72a8 100644 --- a/src/tint.c +++ b/src/tint.c @@ -58,7 +58,7 @@ void init (int argc, char *argv[]) exit(0); } if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { - printf("tint2 version 0.7.svn\n"); + printf("tint2 version 0.8\n"); exit(0); } if (!strcmp(argv[i], "-c")) { @@ -241,26 +241,61 @@ void window_action (Task *tsk, int action) } +int tint2_handles_click(Panel* panel, XButtonEvent* e) +{ + Task* task = click_task(panel, e->x, e->y); + if (task) { + if( (e->button == 1) + || (e->button == 2 && mouse_middle != 0) + || (e->button == 3 && mouse_right != 0) + || (e->button == 4 && mouse_scroll_up != 0) + || (e->button == 5 && mouse_scroll_down !=0) ) + { + return 1; + } + else + return 0; + } + // no task clicked --> check if taskbar clicked + Taskbar *tskbar = click_taskbar(panel, e->x, e->y); + if (tskbar && e->button == 1 && panel_mode == MULTI_DESKTOP) + return 1; + if (click_clock(panel, e->x, e->y)) { + if ( (e->button == 1 && clock_lclick_command) || (e->button == 2 && clock_rclick_command) ) + return 1; + else + return 0; + } + return 0; +} + + +void forward_click(XEvent* e) +{ + // forward the click to the desktop window (thanks conky) + XUngrabPointer(server.dsp, e->xbutton.time); + e->xbutton.window = server.root_win; + // icewm doesn't open under the mouse. + // and xfce doesn't open at all. + e->xbutton.x = e->xbutton.x_root; + e->xbutton.y = e->xbutton.y_root; + //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y); + //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time); + XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e); +} + + void event_button_press (XEvent *e) { Panel *panel = get_panel(e->xany.window); if (!panel) return; - task_drag = click_task(panel, e->xbutton.x, e->xbutton.y); - if (wm_menu && !task_drag && !click_clock(panel, e->xbutton.x, e->xbutton.y) && (e->xbutton.button != 1) ) { - // forward the click to the desktop window (thanks conky) - XUngrabPointer(server.dsp, e->xbutton.time); - e->xbutton.window = server.root_win; - // icewm doesn't open under the mouse. - // and xfce doesn't open at all. - e->xbutton.x = e->xbutton.x_root; - e->xbutton.y = e->xbutton.y_root; - //printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y); - //XSetInputFocus(server.dsp, e->xbutton.window, RevertToParent, e->xbutton.time); - XSendEvent(server.dsp, e->xbutton.window, False, ButtonPressMask, e); + if (wm_menu && !tint2_handles_click(panel, &e->xbutton) ) { + forward_click(e); return; } + task_drag = click_task(panel, e->xbutton.x, e->xbutton.y); XLowerWindow (server.dsp, panel->main_win); } @@ -271,6 +306,12 @@ void event_button_release (XEvent *e) Panel *panel = get_panel(e->xany.window); if (!panel) return; + if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) { + forward_click(e); + task_drag = 0; + return; + } + int action = TOGGLE_ICONIFY; switch (e->xbutton.button) { case 2: @@ -359,6 +400,7 @@ void event_property_notify (XEvent *e) panel1[i].area.resize = 1; } task_refresh_tasklist(); + active_task(); panel_refresh = 1; } // Change desktop @@ -369,8 +411,11 @@ void event_property_notify (XEvent *e) Panel *panel = &panel1[i]; if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) { // redraw both taskbar - panel->taskbar[old_desktop].area.is_active = 0; - panel->taskbar[old_desktop].area.resize = 1; + 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.resize = 1; + } panel->taskbar[server.desktop].area.is_active = 1; panel->taskbar[server.desktop].area.resize = 1; panel_refresh = 1; @@ -379,13 +424,15 @@ void event_property_notify (XEvent *e) Taskbar *tskbar; Task *tsk; GSList *l; - tskbar = &panel->taskbar[old_desktop]; - for (l = tskbar->area.list; l ; l = l->next) { - tsk = l->data; - if (tsk->desktop == ALLDESKTOP) { - tsk->area.on_screen = 0; - tskbar->area.resize = 1; - panel_refresh = 1; + if (server.nb_desktop > old_desktop) { + tskbar = &panel->taskbar[old_desktop]; + for (l = tskbar->area.list; l ; l = l->next) { + tsk = l->data; + if (tsk->desktop == ALLDESKTOP) { + tsk->area.on_screen = 0; + tskbar->area.resize = 1; + panel_refresh = 1; + } } } tskbar = &panel->taskbar[server.desktop]; @@ -518,16 +565,12 @@ void event_property_notify (XEvent *e) // Window desktop changed else if (at == server.atom._NET_WM_DESKTOP) { int desktop = window_get_desktop (win); - int active = tsk->area.is_active; //printf(" Window desktop changed %d, %d\n", tsk->desktop, desktop); // bug in windowmaker : send unecessary 'desktop changed' when focus changed if (desktop != tsk->desktop) { remove_task (tsk); tsk = add_task (win); - if (tsk && active) { - tsk->area.is_active = 1; - task_active = tsk; - } + active_task(); panel_refresh = 1; } } @@ -589,9 +632,13 @@ void event_configure_notify (Window win) remove_task (tsk); add_task (win); if (win == window_get_active ()) { - Task *tsk = task_get_task (win); - tsk->area.is_active = 1; - task_active = tsk; + 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; + } } panel_refresh = 1; } @@ -635,8 +682,7 @@ int main (int argc, char *argv[]) int x11_fd, i; Panel *panel; GSList *it; - GSList* timer_iter; - struct timer* timer; + const struct timespec* timeout; init (argc, argv); @@ -669,6 +715,7 @@ int main (int argc, char *argv[]) if (panel_refresh) { panel_refresh = 0; + // QUESTION: do we need this first refresh_systray, because we check refresh_systray once again later... if (refresh_systray) { panel = (Panel*)systray.area.panel; XSetWindowBackgroundPixmap (server.dsp, panel->main_win, None); @@ -695,20 +742,17 @@ int main (int argc, char *argv[]) } // thanks to AngryLlama for the timer - // Create a File Description Set containing x11_fd, and every timer_fd + // Create a File Description Set containing x11_fd FD_ZERO (&fdset); FD_SET (x11_fd, &fdset); - int max_fd = x11_fd; - timer_iter = timer_list; - while (timer_iter) { - timer = timer_iter->data; - max_fd = timer->id > max_fd ? timer->id : max_fd; - FD_SET(timer->id, &fdset); - timer_iter = timer_iter->next; - } + update_next_timeout(); + if (next_timeout.tv_sec >= 0 && next_timeout.tv_nsec >= 0) + timeout = &next_timeout; + else + timeout = 0; // Wait for X Event or a Timer - if (pselect(max_fd+1, &fdset, 0, 0, 0, &empty_mask) > 0) { + if (pselect(x11_fd+1, &fdset, 0, 0, timeout, &empty_mask) > 0) { while (XPending (server.dsp)) { XNextEvent(server.dsp, &e); @@ -726,9 +770,8 @@ int main (int argc, char *argv[]) if (!g_tooltip.enabled) break; Panel* panel = get_panel(e.xmotion.window); Area* area = click_area(panel, e.xmotion.x, e.xmotion.y); - if (area->_get_tooltip_text) { + if (area->_get_tooltip_text) tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root); - } else tooltip_trigger_hide(); break; @@ -786,24 +829,10 @@ int main (int argc, char *argv[]) break; } } - - // we need to iterate over the whole timer list, since fd_set can only be checked with the - // brute force method FD_ISSET for every possible timer - timer_iter = timer_list; - while (timer_iter) { - timer = timer_iter->data; - if (FD_ISSET(timer->id, &fdset)) { - uint64_t dummy; -//printf("reading from timer->id=%d\n", timer->id); - read(timer->id, &dummy, sizeof(uint64_t)); -//printf("Callback timer->_callback\n"); - timer->_callback(); -//printf("Timer callback finished\n"); - } - timer_iter = timer_iter->next; - } } + callback_timeout_expired(); + switch (signal_pending) { case SIGUSR1: // reload config file signal_pending = 0;