2008-10-02 18:47:02 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Tint2 panel
|
2009-01-17 14:07:56 +00:00
|
|
|
*
|
2008-10-02 18:47:02 +00:00
|
|
|
* Copyright (C) 2007 Pål Staurland (staura@gmail.com)
|
|
|
|
* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
|
2009-01-17 14:07:56 +00:00
|
|
|
*
|
2008-10-02 18:47:02 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-11-15 16:55:50 +00:00
|
|
|
#include <stdint.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xlocale.h>
|
2010-01-03 00:33:07 +00:00
|
|
|
#include <X11/extensions/Xdamage.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include <Imlib2.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2010-06-09 15:31:18 +00:00
|
|
|
#include <version.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include "server.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "taskbar.h"
|
2009-02-10 23:16:10 +00:00
|
|
|
#include "systraybar.h"
|
2010-08-02 17:12:07 +00:00
|
|
|
#include "launcher.h"
|
2008-10-02 18:47:02 +00:00
|
|
|
#include "panel.h"
|
2009-09-14 21:28:17 +00:00
|
|
|
#include "tooltip.h"
|
2009-11-15 16:55:50 +00:00
|
|
|
#include "timer.h"
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2010-04-18 12:07:36 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
void signal_handler(int sig)
|
|
|
|
{
|
|
|
|
// signal handler is light as it should be
|
2009-02-07 23:28:13 +00:00
|
|
|
signal_pending = sig;
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-29 16:19:01 +00:00
|
|
|
void init (int argc, char *argv[])
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-11-10 21:11:31 +00:00
|
|
|
int i;
|
2009-08-29 16:19:01 +00:00
|
|
|
|
2010-04-18 12:07:36 +00:00
|
|
|
// set global data
|
2010-04-18 14:28:45 +00:00
|
|
|
default_config();
|
2010-04-18 12:07:36 +00:00
|
|
|
default_timeout();
|
|
|
|
default_systray();
|
|
|
|
memset(&server, 0, sizeof(Server_global));
|
2010-04-23 17:30:49 +00:00
|
|
|
#ifdef ENABLE_BATTERY
|
2010-04-18 12:07:36 +00:00
|
|
|
default_battery();
|
2010-04-23 17:30:49 +00:00
|
|
|
#endif
|
2010-04-18 12:07:36 +00:00
|
|
|
default_clock();
|
2010-08-02 17:12:07 +00:00
|
|
|
default_launcher();
|
2010-04-18 12:07:36 +00:00
|
|
|
default_taskbar();
|
|
|
|
default_tooltip();
|
2010-04-18 14:28:45 +00:00
|
|
|
default_panel();
|
2010-04-18 12:07:36 +00:00
|
|
|
|
2009-08-29 16:19:01 +00:00
|
|
|
// read options
|
2009-11-10 21:11:31 +00:00
|
|
|
for (i = 1; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
|
|
|
|
printf("Usage: tint2 [-c] <config_file>\n");
|
2009-09-08 21:29:32 +00:00
|
|
|
exit(0);
|
2009-11-10 21:11:31 +00:00
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
|
2010-01-15 20:09:35 +00:00
|
|
|
printf("tint2 version %s\n", VERSION_STRING);
|
2009-11-10 21:11:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2009-12-30 23:27:31 +00:00
|
|
|
if (!strcmp(argv[i], "-c")) {
|
2009-11-10 21:11:31 +00:00
|
|
|
i++;
|
|
|
|
if (i < argc)
|
|
|
|
config_path = strdup(argv[i]);
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "-s")) {
|
|
|
|
i++;
|
|
|
|
if (i < argc)
|
|
|
|
snapshot_path = strdup(argv[i]);
|
2009-09-08 21:29:32 +00:00
|
|
|
}
|
2009-08-29 16:19:01 +00:00
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
// Set signal handler
|
2010-04-18 14:28:45 +00:00
|
|
|
signal_pending = 0;
|
2009-11-15 16:55:50 +00:00
|
|
|
struct sigaction sa = { .sa_handler = signal_handler };
|
2010-07-03 07:37:17 +00:00
|
|
|
struct sigaction sa_chld = { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDWAIT };
|
2009-11-15 16:55:50 +00:00
|
|
|
sigaction(SIGUSR1, &sa, 0);
|
|
|
|
sigaction(SIGINT, &sa, 0);
|
|
|
|
sigaction(SIGTERM, &sa, 0);
|
|
|
|
sigaction(SIGHUP, &sa, 0);
|
2010-07-03 07:37:17 +00:00
|
|
|
sigaction(SIGCHLD, &sa_chld, 0);
|
2010-01-05 20:38:49 +00:00
|
|
|
|
2010-06-16 15:00:48 +00:00
|
|
|
// BSD does not support pselect(), therefore we have to use select and hope that we do not
|
|
|
|
// end up in a race condition there (see 'man select()' on a linux machine for more information)
|
2009-11-15 16:55:50 +00:00
|
|
|
// block all signals, such that no race conditions occur before pselect in our main loop
|
2010-01-05 20:38:49 +00:00
|
|
|
// 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);
|
2010-01-03 13:14:25 +00:00
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
|
2010-01-03 13:14:25 +00:00
|
|
|
void init_X11()
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
server.dsp = XOpenDisplay (NULL);
|
|
|
|
if (!server.dsp) {
|
|
|
|
fprintf(stderr, "tint2 exit : could not open display.\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
server_init_atoms ();
|
|
|
|
server.screen = DefaultScreen (server.dsp);
|
2008-10-30 15:39:24 +00:00
|
|
|
server.root_win = RootWindow(server.dsp, server.screen);
|
2009-09-07 21:41:21 +00:00
|
|
|
server.desktop = server_get_current_desktop ();
|
2009-12-30 11:27:29 +00:00
|
|
|
server_init_visual();
|
2009-09-07 21:41:21 +00:00
|
|
|
XSetErrorHandler ((XErrorHandler) server_catch_error);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
imlib_context_set_display (server.dsp);
|
|
|
|
imlib_context_set_visual (server.visual);
|
2009-12-30 11:27:29 +00:00
|
|
|
imlib_context_set_colormap (server.colormap);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
/* Catch events */
|
|
|
|
XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2010-05-04 20:15:46 +00:00
|
|
|
// config file use '.' as decimal separator
|
|
|
|
setlocale(LC_NUMERIC, "POSIX");
|
2009-10-17 19:52:44 +00:00
|
|
|
|
|
|
|
// load default icon
|
2009-11-15 16:55:50 +00:00
|
|
|
gchar *path;
|
2009-10-17 19:52:44 +00:00
|
|
|
const gchar * const *data_dirs;
|
|
|
|
data_dirs = g_get_system_data_dirs ();
|
2010-01-03 13:14:25 +00:00
|
|
|
int i;
|
2009-10-17 19:52:44 +00:00
|
|
|
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))
|
|
|
|
default_icon = imlib_load_image(path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2009-10-23 20:23:11 +00:00
|
|
|
|
|
|
|
// get monitor and desktop config
|
|
|
|
get_monitors();
|
|
|
|
get_desktops();
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
void cleanup()
|
|
|
|
{
|
2010-04-18 12:07:36 +00:00
|
|
|
cleanup_timeout();
|
2009-10-17 19:52:44 +00:00
|
|
|
cleanup_systray();
|
2009-10-30 17:18:44 +00:00
|
|
|
cleanup_tooltip();
|
|
|
|
cleanup_clock();
|
2010-08-02 17:12:07 +00:00
|
|
|
cleanup_launcher();
|
2009-10-30 17:18:44 +00:00
|
|
|
#ifdef ENABLE_BATTERY
|
|
|
|
cleanup_battery();
|
|
|
|
#endif
|
2010-09-12 22:00:00 +00:00
|
|
|
cleanup_panel();
|
2010-04-18 12:07:36 +00:00
|
|
|
cleanup_config();
|
2009-02-07 23:28:13 +00:00
|
|
|
|
2009-10-17 19:52:44 +00:00
|
|
|
if (default_icon) {
|
|
|
|
imlib_context_set_image(default_icon);
|
|
|
|
imlib_free_image();
|
|
|
|
}
|
2010-04-18 14:28:45 +00:00
|
|
|
imlib_context_disconnect_display();
|
2009-02-07 23:28:13 +00:00
|
|
|
|
2009-12-30 16:25:19 +00:00
|
|
|
cleanup_server();
|
2010-01-10 22:16:27 +00:00
|
|
|
if (server.dsp) XCloseDisplay(server.dsp);
|
2009-02-07 23:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-10 21:11:31 +00:00
|
|
|
void get_snapshot(const char *path)
|
|
|
|
{
|
|
|
|
Panel *panel = &panel1[0];
|
|
|
|
|
2010-03-26 23:16:25 +00:00
|
|
|
if (panel->area.width > server.monitor[0].width)
|
|
|
|
panel->area.width = server.monitor[0].width;
|
|
|
|
|
2009-11-10 21:11:31 +00:00
|
|
|
panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
|
2010-09-18 10:41:34 +00:00
|
|
|
rendering(panel);
|
2009-11-10 21:11:31 +00:00
|
|
|
|
|
|
|
Imlib_Image img = NULL;
|
|
|
|
imlib_context_set_drawable(panel->temp_pmap);
|
|
|
|
img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 0);
|
|
|
|
|
|
|
|
imlib_context_set_image(img);
|
2010-03-31 22:13:24 +00:00
|
|
|
if (!panel_horizontal) {
|
|
|
|
// rotate 90° vertical panel
|
|
|
|
imlib_image_flip_horizontal();
|
|
|
|
imlib_image_flip_diagonal();
|
|
|
|
}
|
2009-11-10 21:11:31 +00:00
|
|
|
imlib_save_image(path);
|
2009-11-11 13:46:56 +00:00
|
|
|
imlib_free_image();
|
2009-11-10 21:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
void window_action (Task *tsk, int action)
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
if (!tsk) return;
|
2009-08-29 15:14:55 +00:00
|
|
|
int desk;
|
2009-08-09 15:57:18 +00:00
|
|
|
switch (action) {
|
|
|
|
case CLOSE:
|
|
|
|
set_close (tsk->win);
|
|
|
|
break;
|
|
|
|
case TOGGLE:
|
|
|
|
set_active(tsk->win);
|
|
|
|
break;
|
|
|
|
case ICONIFY:
|
|
|
|
XIconifyWindow (server.dsp, tsk->win, server.screen);
|
|
|
|
break;
|
|
|
|
case TOGGLE_ICONIFY:
|
2009-11-11 17:12:24 +00:00
|
|
|
if (task_active && tsk->win == task_active->win)
|
|
|
|
XIconifyWindow (server.dsp, tsk->win, server.screen);
|
|
|
|
else
|
|
|
|
set_active (tsk->win);
|
2009-08-09 15:57:18 +00:00
|
|
|
break;
|
|
|
|
case SHADE:
|
|
|
|
window_toggle_shade (tsk->win);
|
|
|
|
break;
|
|
|
|
case MAXIMIZE_RESTORE:
|
|
|
|
window_maximize_restore (tsk->win);
|
|
|
|
break;
|
|
|
|
case MAXIMIZE:
|
|
|
|
window_maximize_restore (tsk->win);
|
|
|
|
break;
|
|
|
|
case RESTORE:
|
|
|
|
window_maximize_restore (tsk->win);
|
|
|
|
break;
|
2009-08-29 15:14:55 +00:00
|
|
|
case DESKTOP_LEFT:
|
2009-08-29 15:26:47 +00:00
|
|
|
if ( tsk->desktop == 0 ) break;
|
2009-08-29 15:14:55 +00:00
|
|
|
desk = tsk->desktop - 1;
|
|
|
|
windows_set_desktop(tsk->win, desk);
|
|
|
|
if (desk == server.desktop)
|
|
|
|
set_active(tsk->win);
|
|
|
|
break;
|
|
|
|
case DESKTOP_RIGHT:
|
2009-08-29 15:26:47 +00:00
|
|
|
if (tsk->desktop == server.nb_desktop ) break;
|
2009-08-29 15:14:55 +00:00
|
|
|
desk = tsk->desktop + 1;
|
|
|
|
windows_set_desktop(tsk->win, desk);
|
|
|
|
if (desk == server.desktop)
|
|
|
|
set_active(tsk->win);
|
2009-11-18 05:13:38 +00:00
|
|
|
break;
|
|
|
|
case NEXT_TASK:
|
|
|
|
if (task_active) {
|
|
|
|
Task *tsk1;
|
|
|
|
tsk1 = next_task(task_active);
|
|
|
|
set_active(tsk1->win);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PREV_TASK:
|
|
|
|
if (task_active) {
|
|
|
|
Task *tsk1;
|
|
|
|
tsk1 = prev_task(task_active);
|
|
|
|
set_active(tsk1->win);
|
|
|
|
}
|
2009-08-09 15:57:18 +00:00
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-28 15:49:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-08-02 17:12:07 +00:00
|
|
|
LauncherIcon *icon = click_launcher_icon(panel, e->x, e->y);
|
|
|
|
if (icon) {
|
|
|
|
if (e->button == 1) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no launcher/task clicked --> check if taskbar clicked
|
2009-12-28 15:49:15 +00:00
|
|
|
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)) {
|
2010-01-14 21:24:03 +00:00
|
|
|
if ( (e->button == 1 && clock_lclick_command) || (e->button == 3 && clock_rclick_command) )
|
2009-12-28 15:49:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
void event_button_press (XEvent *e)
|
2009-01-17 14:07:56 +00:00
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
Panel *panel = get_panel(e->xany.window);
|
2009-02-07 23:28:13 +00:00
|
|
|
if (!panel) return;
|
2009-10-26 21:21:54 +00:00
|
|
|
|
2009-08-28 23:14:53 +00:00
|
|
|
|
2009-12-28 15:49:15 +00:00
|
|
|
if (wm_menu && !tint2_handles_click(panel, &e->xbutton) ) {
|
|
|
|
forward_click(e);
|
2009-08-28 23:14:53 +00:00
|
|
|
return;
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
2009-12-28 15:49:15 +00:00
|
|
|
task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
|
2009-08-29 15:14:55 +00:00
|
|
|
|
2010-05-18 08:50:17 +00:00
|
|
|
if (panel_layer == BOTTOM_LAYER)
|
|
|
|
XLowerWindow (server.dsp, panel->main_win);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 22:44:56 +00:00
|
|
|
void event_button_motion_notify (XEvent *e)
|
|
|
|
{
|
|
|
|
Panel * panel = get_panel(e->xany.window);
|
|
|
|
if(!panel || !task_drag)
|
|
|
|
return;
|
2010-02-09 20:19:49 +00:00
|
|
|
|
2010-02-08 22:44:56 +00:00
|
|
|
// Find the taskbar on the event's location
|
|
|
|
Taskbar * event_taskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y);
|
|
|
|
if(event_taskbar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the task on the event's location
|
|
|
|
Task * event_task = click_task(panel, e->xbutton.x, e->xbutton.y);
|
|
|
|
|
|
|
|
// If the event takes place on the same taskbar as the task being dragged
|
|
|
|
if(event_taskbar == task_drag->area.parent) {
|
|
|
|
// Swap the task_drag with the task on the event's location (if they differ)
|
|
|
|
if(event_task && event_task != task_drag) {
|
|
|
|
GSList * drag_iter = g_slist_find(event_taskbar->area.list, task_drag);
|
|
|
|
GSList * task_iter = g_slist_find(event_taskbar->area.list, event_task);
|
|
|
|
if(drag_iter && task_iter) {
|
|
|
|
gpointer temp = task_iter->data;
|
|
|
|
task_iter->data = drag_iter->data;
|
|
|
|
drag_iter->data = temp;
|
|
|
|
event_taskbar->area.resize = 1;
|
|
|
|
panel_refresh = 1;
|
|
|
|
task_dragged = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // The event is on another taskbar than the task being dragged
|
|
|
|
if(task_drag->desktop == ALLDESKTOP || panel_mode != MULTI_DESKTOP)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Taskbar * drag_taskbar = (Taskbar*)task_drag->area.parent;
|
|
|
|
drag_taskbar->area.list = g_slist_remove(drag_taskbar->area.list, task_drag);
|
|
|
|
|
|
|
|
if(event_taskbar->area.posx > drag_taskbar->area.posx || event_taskbar->area.posy > drag_taskbar->area.posy)
|
|
|
|
event_taskbar->area.list = g_slist_prepend(event_taskbar->area.list, task_drag);
|
|
|
|
else
|
|
|
|
event_taskbar->area.list = g_slist_append(event_taskbar->area.list, task_drag);
|
|
|
|
|
|
|
|
// Move task to other desktop (but avoid the 'Window desktop changed' code in 'event_property_notify')
|
|
|
|
task_drag->area.parent = event_taskbar;
|
|
|
|
task_drag->desktop = event_taskbar->desktop;
|
|
|
|
|
|
|
|
windows_set_desktop(task_drag->win, event_taskbar->desktop);
|
|
|
|
|
|
|
|
event_taskbar->area.resize = 1;
|
|
|
|
drag_taskbar->area.resize = 1;
|
|
|
|
task_dragged = 1;
|
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
void event_button_release (XEvent *e)
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
Panel *panel = get_panel(e->xany.window);
|
2009-02-07 23:28:13 +00:00
|
|
|
if (!panel) return;
|
|
|
|
|
2009-12-28 15:49:15 +00:00
|
|
|
if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) {
|
|
|
|
forward_click(e);
|
2010-05-18 08:50:17 +00:00
|
|
|
if (panel_layer == BOTTOM_LAYER)
|
|
|
|
XLowerWindow (server.dsp, panel->main_win);
|
2009-12-28 15:49:15 +00:00
|
|
|
task_drag = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
int action = TOGGLE_ICONIFY;
|
|
|
|
switch (e->xbutton.button) {
|
|
|
|
case 2:
|
|
|
|
action = mouse_middle;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
action = mouse_right;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
action = mouse_scroll_up;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
action = mouse_scroll_down;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
action = mouse_tilt_left;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
action = mouse_tilt_right;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-28 23:14:53 +00:00
|
|
|
|
2009-09-08 21:29:32 +00:00
|
|
|
if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
|
2009-08-28 23:14:53 +00:00
|
|
|
clock_action(e->xbutton.button);
|
2010-05-18 08:50:17 +00:00
|
|
|
if (panel_layer == BOTTOM_LAYER)
|
|
|
|
XLowerWindow (server.dsp, panel->main_win);
|
2009-08-28 23:14:53 +00:00
|
|
|
task_drag = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-02 17:12:07 +00:00
|
|
|
if ( click_launcher(panel, e->xbutton.x, e->xbutton.y)) {
|
|
|
|
LauncherIcon *icon = click_launcher_icon(panel, e->xbutton.x, e->xbutton.y);
|
|
|
|
if (icon) {
|
|
|
|
launcher_action(icon);
|
|
|
|
}
|
|
|
|
task_drag = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-28 23:14:53 +00:00
|
|
|
Taskbar *tskbar;
|
2009-09-08 21:29:32 +00:00
|
|
|
if ( !(tskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y)) ) {
|
2009-08-28 23:14:53 +00:00
|
|
|
// TODO: check better solution to keep window below
|
2010-05-18 08:50:17 +00:00
|
|
|
if (panel_layer == BOTTOM_LAYER)
|
|
|
|
XLowerWindow (server.dsp, panel->main_win);
|
2009-08-28 23:14:53 +00:00
|
|
|
task_drag = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-08 22:44:56 +00:00
|
|
|
// drag and drop task
|
|
|
|
if (task_dragged) {
|
|
|
|
task_drag = 0;
|
|
|
|
task_dragged = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-09 20:19:49 +00:00
|
|
|
// switch desktop
|
|
|
|
if (panel_mode == MULTI_DESKTOP) {
|
|
|
|
if (tskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT && action != DESKTOP_RIGHT)
|
|
|
|
set_desktop (tskbar->desktop);
|
|
|
|
}
|
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
// action on task
|
2009-09-08 21:29:32 +00:00
|
|
|
window_action( click_task(panel, e->xbutton.x, e->xbutton.y), action);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
// to keep window below
|
2010-05-18 08:50:17 +00:00
|
|
|
if (panel_layer == BOTTOM_LAYER)
|
|
|
|
XLowerWindow (server.dsp, panel->main_win);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 20:04:43 +00:00
|
|
|
void event_property_notify (XEvent *e)
|
2009-01-17 14:07:56 +00:00
|
|
|
{
|
2010-01-09 18:29:00 +00:00
|
|
|
int i;
|
2009-09-07 21:41:21 +00:00
|
|
|
Task *tsk;
|
|
|
|
Window win = e->xproperty.window;
|
|
|
|
Atom at = e->xproperty.atom;
|
|
|
|
|
|
|
|
if (win == server.root_win) {
|
|
|
|
if (!server.got_root_win) {
|
|
|
|
XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
|
|
|
|
server.got_root_win = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change number of desktops
|
|
|
|
else if (at == server.atom._NET_NUMBER_OF_DESKTOPS) {
|
2010-09-19 08:34:24 +00:00
|
|
|
if (!taskbar_enabled) return;
|
2009-09-07 21:41:21 +00:00
|
|
|
server.nb_desktop = server_get_number_of_desktop ();
|
|
|
|
cleanup_taskbar();
|
2009-02-07 23:28:13 +00:00
|
|
|
init_taskbar();
|
2009-02-10 23:16:10 +00:00
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
2010-09-19 08:34:24 +00:00
|
|
|
init_taskbar_panel(&panel1[i]);
|
|
|
|
set_panel_items_order(&panel1[i]);
|
2010-09-23 18:09:30 +00:00
|
|
|
visible_taskbar(&panel1[i]);
|
2009-02-13 21:54:42 +00:00
|
|
|
panel1[i].area.resize = 1;
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
2009-02-07 23:28:13 +00:00
|
|
|
task_refresh_tasklist();
|
2009-12-29 19:55:25 +00:00
|
|
|
active_task();
|
2009-02-07 23:28:13 +00:00
|
|
|
panel_refresh = 1;
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
|
|
|
// Change desktop
|
|
|
|
else if (at == server.atom._NET_CURRENT_DESKTOP) {
|
2010-09-19 08:34:24 +00:00
|
|
|
if (!taskbar_enabled) return;
|
2009-09-26 11:04:02 +00:00
|
|
|
int old_desktop = server.desktop;
|
2009-09-07 21:41:21 +00:00
|
|
|
server.desktop = server_get_current_desktop ();
|
2009-09-25 21:40:06 +00:00
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
2009-09-07 21:41:21 +00:00
|
|
|
Panel *panel = &panel1[i];
|
2010-09-23 18:09:30 +00:00
|
|
|
if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.bg != panel->g_taskbar.bg_active) {
|
2009-09-26 11:04:02 +00:00
|
|
|
// redraw both taskbar
|
2009-12-29 22:04:24 +00:00
|
|
|
if (server.nb_desktop > old_desktop) {
|
|
|
|
// can happen if last desktop is deleted and we've been on the last desktop
|
2010-01-09 00:11:01 +00:00
|
|
|
panel->taskbar[old_desktop].area.bg = panel->g_taskbar.bg;
|
2009-12-29 22:04:24 +00:00
|
|
|
panel->taskbar[old_desktop].area.resize = 1;
|
|
|
|
}
|
2010-01-09 00:11:01 +00:00
|
|
|
panel->taskbar[server.desktop].area.bg = panel->g_taskbar.bg_active;
|
2009-10-31 11:58:45 +00:00
|
|
|
panel->taskbar[server.desktop].area.resize = 1;
|
2009-09-25 21:40:06 +00:00
|
|
|
panel_refresh = 1;
|
2009-09-26 11:04:02 +00:00
|
|
|
}
|
|
|
|
// check ALLDESKTOP task => resize taskbar
|
|
|
|
Taskbar *tskbar;
|
|
|
|
Task *tsk;
|
|
|
|
GSList *l;
|
2009-12-29 22:04:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-09-26 11:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tskbar = &panel->taskbar[server.desktop];
|
|
|
|
for (l = tskbar->area.list; l ; l = l->next) {
|
|
|
|
tsk = l->data;
|
|
|
|
if (tsk->desktop == ALLDESKTOP) {
|
|
|
|
tsk->area.on_screen = 1;
|
|
|
|
tskbar->area.resize = 1;
|
2009-08-30 15:40:02 +00:00
|
|
|
}
|
2009-09-25 21:40:06 +00:00
|
|
|
}
|
2010-09-23 18:09:30 +00:00
|
|
|
if (panel_mode != MULTI_DESKTOP)
|
|
|
|
visible_taskbar(panel);
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Window list
|
|
|
|
else if (at == server.atom._NET_CLIENT_LIST) {
|
|
|
|
task_refresh_tasklist();
|
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
// Change active
|
|
|
|
else if (at == server.atom._NET_ACTIVE_WINDOW) {
|
2009-10-23 21:28:44 +00:00
|
|
|
active_task();
|
2009-09-07 21:41:21 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
else if (at == server.atom._XROOTPMAP_ID) {
|
2009-06-13 19:39:41 +00:00
|
|
|
// change Wallpaper
|
2009-02-07 23:28:13 +00:00
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
set_panel_background(&panel1[i]);
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tsk = task_get_task (win);
|
|
|
|
if (!tsk) {
|
2009-11-11 17:12:24 +00:00
|
|
|
if (at != server.atom._NET_WM_STATE)
|
2009-09-07 21:41:21 +00:00
|
|
|
return;
|
2009-11-11 18:25:55 +00:00
|
|
|
else {
|
|
|
|
// xfce4 sends _NET_WM_STATE after minimized to tray, so we need to check if window is mapped
|
|
|
|
// if it is mapped and not set as skip_taskbar, we must add it to our task list
|
|
|
|
XWindowAttributes wa;
|
|
|
|
XGetWindowAttributes(server.dsp, win, &wa);
|
|
|
|
if (wa.map_state == IsViewable && !window_is_skip_taskbar(win)) {
|
|
|
|
if ( (tsk = add_task(win)) )
|
|
|
|
panel_refresh = 1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 17:45:50 +00:00
|
|
|
else
|
|
|
|
return;
|
2009-11-11 17:12:24 +00:00
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
|
|
|
//printf("atom root_win = %s, %s\n", XGetAtomName(server.dsp, at), tsk->title);
|
|
|
|
|
|
|
|
// Window title changed
|
|
|
|
if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {
|
2009-02-07 23:28:13 +00:00
|
|
|
get_title(tsk);
|
2010-01-15 15:31:07 +00:00
|
|
|
if (g_tooltip.mapped && (g_tooltip.area == (Area*)tsk)) {
|
|
|
|
tooltip_copy_text((Area*)tsk);
|
|
|
|
tooltip_update();
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
2009-02-25 20:04:43 +00:00
|
|
|
// Demand attention
|
2009-09-07 21:41:21 +00:00
|
|
|
else if (at == server.atom._NET_WM_STATE) {
|
|
|
|
if (window_is_urgent (win)) {
|
2009-11-11 20:09:34 +00:00
|
|
|
add_urgent(tsk);
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
if (window_is_skip_taskbar(win)) {
|
|
|
|
remove_task( tsk );
|
2009-09-08 18:58:34 +00:00
|
|
|
panel_refresh = 1;
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
2010-01-09 00:11:01 +00:00
|
|
|
else if (at == server.atom.WM_STATE) {
|
|
|
|
// Iconic state
|
2010-01-09 18:29:00 +00:00
|
|
|
int state = (task_active && tsk->win == task_active->win ? TASK_ACTIVE : TASK_NORMAL);
|
2010-01-09 00:11:01 +00:00
|
|
|
if (window_is_iconified(win))
|
|
|
|
state = TASK_ICONIFIED;
|
2010-01-09 18:29:00 +00:00
|
|
|
set_task_state(tsk, state);
|
2010-01-09 00:11:01 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
// Window icon changed
|
|
|
|
else if (at == server.atom._NET_WM_ICON) {
|
|
|
|
get_icon(tsk);
|
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
// Window desktop changed
|
|
|
|
else if (at == server.atom._NET_WM_DESKTOP) {
|
2009-06-06 21:03:00 +00:00
|
|
|
int desktop = window_get_desktop (win);
|
|
|
|
//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);
|
2009-06-29 19:50:29 +00:00
|
|
|
tsk = add_task (win);
|
2009-12-29 19:55:25 +00:00
|
|
|
active_task();
|
2009-06-06 21:03:00 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
2009-09-15 20:11:13 +00:00
|
|
|
else if (at == server.atom.WM_HINTS) {
|
|
|
|
XWMHints* wmhints = XGetWMHints(server.dsp, win);
|
2009-09-16 11:00:23 +00:00
|
|
|
if (wmhints && wmhints->flags & XUrgencyHint) {
|
2009-11-11 20:09:34 +00:00
|
|
|
add_urgent(tsk);
|
2009-09-15 20:11:13 +00:00
|
|
|
}
|
|
|
|
XFree(wmhints);
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
if (!server.got_root_win) server.root_win = RootWindow (server.dsp, server.screen);
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-28 23:04:53 +00:00
|
|
|
void event_expose (XEvent *e)
|
|
|
|
{
|
2009-11-16 10:06:45 +00:00
|
|
|
Panel *panel;
|
|
|
|
panel = get_panel(e->xany.window);
|
|
|
|
if (!panel) return;
|
|
|
|
// TODO : one panel_refresh per panel ?
|
|
|
|
panel_refresh = 1;
|
2009-02-28 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
void event_configure_notify (Window win)
|
2009-01-17 14:07:56 +00:00
|
|
|
{
|
2009-09-27 16:57:19 +00:00
|
|
|
// change in root window (xrandr)
|
2009-09-27 13:33:31 +00:00
|
|
|
if (win == server.root_win) {
|
2010-04-18 14:28:45 +00:00
|
|
|
signal_pending = SIGUSR1;
|
2009-09-27 16:57:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'win' is a trayer icon
|
|
|
|
TrayWindow *traywin;
|
|
|
|
GSList *l;
|
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
|
|
|
traywin = (TrayWindow*)l->data;
|
2010-01-03 00:33:07 +00:00
|
|
|
if (traywin->tray_id == win) {
|
2009-09-27 16:57:19 +00:00
|
|
|
//printf("move tray %d\n", traywin->x);
|
|
|
|
XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, traywin->width, traywin->height);
|
2010-01-03 00:33:07 +00:00
|
|
|
XResizeWindow(server.dsp, traywin->tray_id, traywin->width, traywin->height);
|
2009-09-27 13:33:31 +00:00
|
|
|
panel_refresh = 1;
|
2009-09-27 16:57:19 +00:00
|
|
|
return;
|
2009-02-13 21:54:42 +00:00
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
2009-09-27 16:57:19 +00:00
|
|
|
|
|
|
|
// 'win' move in another monitor
|
|
|
|
if (nb_panel == 1) return;
|
|
|
|
Task *tsk = task_get_task (win);
|
|
|
|
if (!tsk) return;
|
|
|
|
|
|
|
|
Panel *p = tsk->area.panel;
|
|
|
|
if (p->monitor != window_get_monitor (win)) {
|
|
|
|
remove_task (tsk);
|
2010-01-10 15:00:40 +00:00
|
|
|
tsk = add_task (win);
|
2009-09-27 16:57:19 +00:00
|
|
|
if (win == window_get_active ()) {
|
2010-01-09 18:29:00 +00:00
|
|
|
set_task_state(tsk, TASK_ACTIVE);
|
|
|
|
task_active = tsk;
|
2009-09-27 16:57:19 +00:00
|
|
|
}
|
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-08 21:29:32 +00:00
|
|
|
void dnd_message(XClientMessageEvent *e)
|
|
|
|
{
|
|
|
|
Panel *panel = get_panel(e->window);
|
|
|
|
int x, y, mapX, mapY;
|
|
|
|
Window child;
|
|
|
|
x = (e->data.l[2] >> 16) & 0xFFFF;
|
|
|
|
y = e->data.l[2] & 0xFFFF;
|
|
|
|
XTranslateCoordinates(server.dsp, server.root_win, e->window, x, y, &mapX, &mapY, &child);
|
|
|
|
Task* task = click_task(panel, mapX, mapY);
|
|
|
|
if (task) {
|
|
|
|
if (task->desktop != server.desktop )
|
|
|
|
set_desktop (task->desktop);
|
|
|
|
window_action(task, TOGGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// send XdndStatus event to get more XdndPosition events
|
|
|
|
XClientMessageEvent se;
|
|
|
|
se.type = ClientMessage;
|
|
|
|
se.window = e->data.l[0];
|
|
|
|
se.message_type = server.atom.XdndStatus;
|
|
|
|
se.format = 32;
|
|
|
|
se.data.l[0] = e->window; // XID of the target window
|
|
|
|
se.data.l[1] = 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
|
|
|
|
se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
|
|
|
|
se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
|
|
|
|
se.data.l[4] = None; // None = drop will not be accepted
|
|
|
|
XSendEvent(server.dsp, e->data.l[0], False, NoEventMask, (XEvent*)&se);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
XEvent e;
|
2010-01-17 13:43:44 +00:00
|
|
|
XClientMessageEvent *ev;
|
2009-11-16 09:27:44 +00:00
|
|
|
fd_set fdset;
|
2009-09-07 21:41:21 +00:00
|
|
|
int x11_fd, i;
|
|
|
|
Panel *panel;
|
2009-02-27 22:18:30 +00:00
|
|
|
GSList *it;
|
2010-01-05 20:38:49 +00:00
|
|
|
struct timeval* timeout;
|
2010-06-26 12:35:35 +00:00
|
|
|
int hidden_dnd = 0;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2010-04-18 14:28:45 +00:00
|
|
|
start:
|
2010-01-03 13:14:25 +00:00
|
|
|
init (argc, argv);
|
2010-03-20 08:30:41 +00:00
|
|
|
init_X11();
|
|
|
|
|
2009-12-30 23:27:31 +00:00
|
|
|
i = 0;
|
2009-09-07 21:41:21 +00:00
|
|
|
if (config_path)
|
|
|
|
i = config_read_file (config_path);
|
2009-08-29 16:19:01 +00:00
|
|
|
else
|
|
|
|
i = config_read ();
|
|
|
|
if (!i) {
|
|
|
|
fprintf(stderr, "usage: tint2 [-c] <config_file>\n");
|
|
|
|
cleanup();
|
|
|
|
exit(1);
|
2009-06-20 14:41:06 +00:00
|
|
|
}
|
2009-12-30 23:27:31 +00:00
|
|
|
|
2009-10-30 17:18:44 +00:00
|
|
|
init_panel();
|
2009-11-10 21:11:31 +00:00
|
|
|
if (snapshot_path) {
|
|
|
|
get_snapshot(snapshot_path);
|
2009-08-29 16:19:01 +00:00
|
|
|
cleanup();
|
|
|
|
exit(0);
|
|
|
|
}
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2010-01-03 00:33:07 +00:00
|
|
|
int damage_event, damage_error;
|
|
|
|
XDamageQueryExtension(server.dsp, &damage_event, &damage_error);
|
2009-09-07 21:41:21 +00:00
|
|
|
x11_fd = ConnectionNumber(server.dsp);
|
|
|
|
XSync(server.dsp, False);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2010-01-05 20:38:49 +00:00
|
|
|
// sigset_t empty_mask;
|
|
|
|
// sigemptyset(&empty_mask);
|
2009-11-15 16:55:50 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
while (1) {
|
2009-11-16 10:06:45 +00:00
|
|
|
if (panel_refresh) {
|
|
|
|
panel_refresh = 0;
|
|
|
|
|
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
panel = &panel1[i];
|
|
|
|
|
2010-01-12 08:24:24 +00:00
|
|
|
if (panel->is_hidden) {
|
2010-01-05 20:38:49 +00:00
|
|
|
XCopyArea(server.dsp, panel->hidden_pixmap, panel->main_win, server.gc, 0, 0, panel->hidden_width, panel->hidden_height, 0, 0);
|
2010-01-12 08:24:24 +00:00
|
|
|
XSetWindowBackgroundPixmap(server.dsp, panel->main_win, panel->hidden_pixmap);
|
|
|
|
}
|
2010-01-05 20:38:49 +00:00
|
|
|
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);
|
2010-09-18 10:41:34 +00:00
|
|
|
rendering(panel);
|
2010-01-05 20:38:49 +00:00
|
|
|
XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
|
|
|
|
}
|
2009-11-16 10:06:45 +00:00
|
|
|
}
|
|
|
|
XFlush (server.dsp);
|
|
|
|
|
2010-01-05 20:38:49 +00:00
|
|
|
panel = (Panel*)systray.area.panel;
|
2010-01-31 16:56:54 +00:00
|
|
|
if (refresh_systray && panel && !panel->is_hidden) {
|
2009-11-16 10:06:45 +00:00
|
|
|
refresh_systray = 0;
|
|
|
|
// tint2 doen't draw systray icons. it just redraw background.
|
|
|
|
XSetWindowBackgroundPixmap (server.dsp, panel->main_win, panel->temp_pmap);
|
|
|
|
// force icon's refresh
|
|
|
|
refresh_systray_icon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
// thanks to AngryLlama for the timer
|
2009-12-27 20:33:02 +00:00
|
|
|
// Create a File Description Set containing x11_fd
|
2009-11-16 09:27:44 +00:00
|
|
|
FD_ZERO (&fdset);
|
|
|
|
FD_SET (x11_fd, &fdset);
|
2009-12-27 20:33:02 +00:00
|
|
|
update_next_timeout();
|
2010-01-05 20:38:49 +00:00
|
|
|
if (next_timeout.tv_sec >= 0 && next_timeout.tv_usec >= 0)
|
2009-12-27 20:33:02 +00:00
|
|
|
timeout = &next_timeout;
|
|
|
|
else
|
|
|
|
timeout = 0;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
// Wait for X Event or a Timer
|
2010-01-05 20:38:49 +00:00
|
|
|
if (select(x11_fd+1, &fdset, 0, 0, timeout) > 0) {
|
2009-09-07 21:41:21 +00:00
|
|
|
while (XPending (server.dsp)) {
|
|
|
|
XNextEvent(server.dsp, &e);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2010-01-05 20:38:49 +00:00
|
|
|
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);
|
2010-06-20 15:56:04 +00:00
|
|
|
if (panel->is_hidden) {
|
2010-06-26 12:35:35 +00:00
|
|
|
if (e.type == ClientMessage && e.xclient.message_type == server.atom.XdndPosition) {
|
|
|
|
hidden_dnd = 1;
|
2010-06-20 15:56:04 +00:00
|
|
|
autohide_show(panel);
|
2010-06-26 12:35:35 +00:00
|
|
|
}
|
2010-06-20 15:56:04 +00:00
|
|
|
else
|
|
|
|
continue; // discard further processing of this event because the panel is not visible yet
|
|
|
|
}
|
2010-06-26 12:35:35 +00:00
|
|
|
else if (hidden_dnd && e.type == ClientMessage && e.xclient.message_type == server.atom.XdndLeave) {
|
|
|
|
hidden_dnd = 0;
|
|
|
|
autohide_hide(panel);
|
|
|
|
}
|
2010-01-05 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
switch (e.type) {
|
|
|
|
case ButtonPress:
|
2010-01-05 20:38:49 +00:00
|
|
|
tooltip_hide(0);
|
2009-09-07 21:41:21 +00:00
|
|
|
event_button_press (&e);
|
|
|
|
break;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
case ButtonRelease:
|
|
|
|
event_button_release(&e);
|
|
|
|
break;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2009-09-14 21:28:17 +00:00
|
|
|
case MotionNotify: {
|
2010-02-08 22:44:56 +00:00
|
|
|
unsigned int button_mask = Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
|
|
|
|
if (e.xmotion.state & button_mask)
|
|
|
|
event_button_motion_notify (&e);
|
2010-02-09 20:19:49 +00:00
|
|
|
|
2009-10-30 20:54:29 +00:00
|
|
|
if (!g_tooltip.enabled) break;
|
2009-09-14 21:28:17 +00:00
|
|
|
Panel* panel = get_panel(e.xmotion.window);
|
2009-11-16 17:17:53 +00:00
|
|
|
Area* area = click_area(panel, e.xmotion.x, e.xmotion.y);
|
2009-12-16 09:04:50 +00:00
|
|
|
if (area->_get_tooltip_text)
|
2010-08-07 12:17:56 +00:00
|
|
|
tooltip_trigger_show(area, panel, &e);
|
2009-09-14 21:28:17 +00:00
|
|
|
else
|
|
|
|
tooltip_trigger_hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LeaveNotify:
|
2010-01-05 20:38:49 +00:00
|
|
|
if (g_tooltip.enabled)
|
|
|
|
tooltip_trigger_hide();
|
2009-09-14 21:28:17 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
case Expose:
|
|
|
|
event_expose(&e);
|
|
|
|
break;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
case PropertyNotify:
|
|
|
|
event_property_notify(&e);
|
|
|
|
break;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
case ConfigureNotify:
|
2009-09-27 13:33:31 +00:00
|
|
|
event_configure_notify (e.xconfigure.window);
|
2009-09-07 21:41:21 +00:00
|
|
|
break;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2009-06-13 19:39:41 +00:00
|
|
|
case ReparentNotify:
|
2009-10-31 11:58:45 +00:00
|
|
|
if (!systray_enabled)
|
2009-06-29 18:39:44 +00:00
|
|
|
break;
|
|
|
|
panel = (Panel*)systray.area.panel;
|
|
|
|
if (e.xany.window == panel->main_win) // reparented to us
|
2009-06-13 19:39:41 +00:00
|
|
|
break;
|
2009-06-29 18:39:44 +00:00
|
|
|
// FIXME: 'reparent to us' badly detected => disabled
|
|
|
|
break;
|
2009-02-10 23:16:10 +00:00
|
|
|
case UnmapNotify:
|
|
|
|
case DestroyNotify:
|
2010-01-17 13:43:44 +00:00
|
|
|
if (e.xany.window == server.composite_manager) {
|
2010-04-18 14:49:50 +00:00
|
|
|
// Stop real_transparency
|
|
|
|
signal_pending = SIGUSR1;
|
2010-01-17 13:43:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-18 18:06:29 +00:00
|
|
|
if (e.xany.window == g_tooltip.window || !systray_enabled)
|
2009-06-13 19:39:41 +00:00
|
|
|
break;
|
2009-02-27 22:18:30 +00:00
|
|
|
for (it = systray.list_icons; it; it = g_slist_next(it)) {
|
2010-01-03 00:33:07 +00:00
|
|
|
if (((TrayWindow*)it->data)->tray_id == e.xany.window) {
|
2009-03-01 19:18:35 +00:00
|
|
|
remove_icon((TrayWindow*)it->data);
|
2009-02-10 23:16:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-27 22:18:30 +00:00
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ClientMessage:
|
2010-01-18 21:11:05 +00:00
|
|
|
ev = &e.xclient;
|
2010-01-17 13:43:44 +00:00
|
|
|
if (ev->data.l[1] == server.atom._NET_WM_CM_S0) {
|
|
|
|
if (ev->data.l[2] == None)
|
2010-04-18 14:49:50 +00:00
|
|
|
// Stop real_transparency
|
|
|
|
signal_pending = SIGUSR1;
|
2010-01-17 13:43:44 +00:00
|
|
|
else
|
2010-04-18 14:49:50 +00:00
|
|
|
// Start real_transparency
|
|
|
|
signal_pending = SIGUSR1;
|
2010-01-17 13:43:44 +00:00
|
|
|
}
|
2010-09-18 18:06:29 +00:00
|
|
|
if (systray_enabled && e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
|
2009-02-10 23:16:10 +00:00
|
|
|
net_message(&e.xclient);
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
2009-09-08 21:29:32 +00:00
|
|
|
else if (e.xclient.message_type == server.atom.XdndPosition) {
|
|
|
|
dnd_message(&e.xclient);
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
break;
|
2010-01-03 00:33:07 +00:00
|
|
|
|
|
|
|
default:
|
2010-01-06 19:30:55 +00:00
|
|
|
if (e.type == XDamageNotify+damage_event) {
|
2010-01-10 22:16:27 +00:00
|
|
|
// union needed to avoid strict-aliasing warnings by gcc
|
|
|
|
union { XEvent e; XDamageNotifyEvent de; } event_union = {.e=e};
|
2010-01-06 19:30:55 +00:00
|
|
|
TrayWindow *traywin;
|
|
|
|
GSList *l;
|
2010-01-10 22:16:27 +00:00
|
|
|
XDamageNotifyEvent* de = &event_union.de;
|
2010-01-06 19:30:55 +00:00
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
|
|
|
traywin = (TrayWindow*)l->data;
|
2010-01-30 23:06:07 +00:00
|
|
|
if ( traywin->id == de->drawable ) {
|
2010-01-06 19:30:55 +00:00
|
|
|
systray_render_icon(traywin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-12-27 20:33:02 +00:00
|
|
|
callback_timeout_expired();
|
|
|
|
|
2010-04-18 14:28:45 +00:00
|
|
|
if (signal_pending) {
|
|
|
|
cleanup();
|
|
|
|
if (signal_pending == SIGUSR1) {
|
|
|
|
// restart tint2
|
|
|
|
// SIGUSR1 used when : user's signal, composite manager stop/start or xrandr
|
2010-04-18 14:49:50 +00:00
|
|
|
FD_CLR (x11_fd, &fdset); // not sure if needed
|
2010-04-18 14:28:45 +00:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// SIGINT, SIGTERM, SIGHUP
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|