2009-01-20 21:16:54 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* Tint2 : systraybar
|
|
|
|
*
|
2010-11-02 11:40:50 +00:00
|
|
|
* Copyright (C) 2009 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
|
2009-06-19 21:08:34 +00:00
|
|
|
* based on 'docker-1.5' from Ben Jansens.
|
2009-01-20 21:16:54 +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 <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <Imlib2.h>
|
2010-01-03 00:33:07 +00:00
|
|
|
#include <X11/extensions/Xdamage.h>
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
2010-01-31 14:04:58 +00:00
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
|
2015-05-30 11:23:20 +00:00
|
|
|
|
2009-01-20 21:16:54 +00:00
|
|
|
#include "systraybar.h"
|
|
|
|
#include "server.h"
|
2009-02-10 23:16:10 +00:00
|
|
|
#include "panel.h"
|
2009-01-20 21:16:54 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
GSList *icons;
|
2009-01-20 21:16:54 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
/* defined in the systray spec */
|
|
|
|
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
|
|
|
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
|
|
|
|
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
|
|
|
|
|
2009-02-25 20:04:43 +00:00
|
|
|
// selection window
|
2010-01-07 21:23:15 +00:00
|
|
|
Window net_sel_win = None;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2009-02-27 22:18:30 +00:00
|
|
|
// freedesktop specification doesn't allow multi systray
|
|
|
|
Systraybar systray;
|
2009-06-20 15:08:33 +00:00
|
|
|
int refresh_systray;
|
2009-10-30 17:18:44 +00:00
|
|
|
int systray_enabled;
|
2010-04-16 18:50:03 +00:00
|
|
|
int systray_max_icon_size;
|
2015-01-23 18:40:31 +00:00
|
|
|
int systray_monitor;
|
2015-05-13 19:17:02 +00:00
|
|
|
int chrono;
|
2015-06-07 09:44:43 +00:00
|
|
|
int systray_composited;
|
2010-01-06 19:30:55 +00:00
|
|
|
// background pixmap if we render ourselves the icons
|
2010-04-18 12:07:36 +00:00
|
|
|
static Pixmap render_background;
|
2010-01-06 19:30:55 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2010-04-18 12:07:36 +00:00
|
|
|
void default_systray()
|
|
|
|
{
|
|
|
|
memset(&systray, 0, sizeof(Systraybar));
|
|
|
|
render_background = 0;
|
2015-05-13 19:17:02 +00:00
|
|
|
chrono = 0;
|
2010-04-18 12:07:36 +00:00
|
|
|
systray.alpha = 100;
|
2015-05-13 19:17:02 +00:00
|
|
|
systray.sort = SYSTRAY_SORT_LEFT2RIGHT;
|
2010-04-18 12:07:36 +00:00
|
|
|
systray.area._draw_foreground = draw_systray;
|
2010-09-25 21:18:47 +00:00
|
|
|
systray.area._on_change_layout = on_change_systray;
|
2010-08-08 14:06:15 +00:00
|
|
|
systray.area.size_mode = SIZE_BY_CONTENT;
|
2010-04-18 12:07:36 +00:00
|
|
|
systray.area._resize = resize_systray;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup_systray()
|
|
|
|
{
|
2010-04-22 15:08:21 +00:00
|
|
|
stop_net();
|
2010-04-18 12:07:36 +00:00
|
|
|
systray_enabled = 0;
|
|
|
|
systray_max_icon_size = 0;
|
2015-01-23 18:40:31 +00:00
|
|
|
systray_monitor = 0;
|
2010-04-18 12:07:36 +00:00
|
|
|
systray.area.on_screen = 0;
|
|
|
|
free_area(&systray.area);
|
|
|
|
if (render_background) {
|
|
|
|
XFreePixmap(server.dsp, render_background);
|
|
|
|
render_background = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-15 17:22:48 +00:00
|
|
|
void init_systray()
|
2009-02-10 23:16:10 +00:00
|
|
|
{
|
2009-10-30 17:18:44 +00:00
|
|
|
if (!systray_enabled)
|
2009-02-27 22:18:30 +00:00
|
|
|
return;
|
2009-02-15 17:22:48 +00:00
|
|
|
|
2015-06-12 10:24:19 +00:00
|
|
|
systray_composited = !server.disable_transparency && server.visual32 && server.colormap32;
|
2015-06-07 09:44:43 +00:00
|
|
|
printf("Systray composited rendering %s\n", systray_composited ? "on" : "off");
|
|
|
|
|
|
|
|
if (!systray_composited) {
|
|
|
|
printf("systray_asb forced to 100 0 0\n");
|
2010-02-28 07:58:50 +00:00
|
|
|
systray.alpha = 100;
|
|
|
|
systray.brightness = systray.saturation = 0;
|
|
|
|
}
|
2015-06-07 09:44:43 +00:00
|
|
|
|
|
|
|
start_net();
|
2009-10-18 17:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init_systray_panel(void *p)
|
|
|
|
{
|
|
|
|
systray.area.parent = p;
|
|
|
|
systray.area.panel = p;
|
2015-04-11 09:51:10 +00:00
|
|
|
if (!systray.area.bg)
|
2011-01-06 23:28:16 +00:00
|
|
|
systray.area.bg = &g_array_index(backgrounds, Background, 0);
|
|
|
|
|
2010-09-18 18:06:29 +00:00
|
|
|
GSList *l;
|
|
|
|
int count = 0;
|
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
2015-05-11 19:19:36 +00:00
|
|
|
if (((TrayWindow*)l->data)->hide)
|
|
|
|
continue;
|
|
|
|
count++;
|
2010-09-18 18:06:29 +00:00
|
|
|
}
|
|
|
|
if (count == 0)
|
2010-09-22 19:33:10 +00:00
|
|
|
hide(&systray.area);
|
2015-06-07 09:44:43 +00:00
|
|
|
else
|
2010-09-22 19:33:10 +00:00
|
|
|
show(&systray.area);
|
2010-09-18 18:06:29 +00:00
|
|
|
refresh_systray = 0;
|
2009-02-15 17:22:48 +00:00
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
|
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
void draw_systray(void *obj, cairo_t *c)
|
2009-06-20 15:08:33 +00:00
|
|
|
{
|
2015-06-07 09:44:43 +00:00
|
|
|
if (systray_composited) {
|
2015-06-07 10:58:29 +00:00
|
|
|
if (render_background)
|
|
|
|
XFreePixmap(server.dsp, render_background);
|
2010-01-06 19:30:55 +00:00
|
|
|
render_background = XCreatePixmap(server.dsp, server.root_win, systray.area.width, systray.area.height, server.depth);
|
2010-01-09 00:11:01 +00:00
|
|
|
XCopyArea(server.dsp, systray.area.pix, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0);
|
2010-01-06 19:30:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 15:08:33 +00:00
|
|
|
refresh_systray = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-16 23:24:25 +00:00
|
|
|
int resize_systray(void *obj)
|
2009-02-28 23:04:53 +00:00
|
|
|
{
|
|
|
|
Systraybar *sysbar = obj;
|
|
|
|
GSList *l;
|
2010-09-18 22:00:16 +00:00
|
|
|
int count;
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal)
|
2010-09-18 22:00:16 +00:00
|
|
|
sysbar->icon_size = sysbar->area.height;
|
2009-06-24 20:17:57 +00:00
|
|
|
else
|
2010-09-18 22:00:16 +00:00
|
|
|
sysbar->icon_size = sysbar->area.width;
|
|
|
|
sysbar->icon_size = sysbar->icon_size - (2 * sysbar->area.bg->border.width) - (2 * sysbar->area.paddingy);
|
|
|
|
if (systray_max_icon_size > 0 && sysbar->icon_size > systray_max_icon_size)
|
|
|
|
sysbar->icon_size = systray_max_icon_size;
|
2009-09-27 21:33:44 +00:00
|
|
|
count = 0;
|
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
2015-05-13 20:58:58 +00:00
|
|
|
if (((TrayWindow*)l->data)->hide)
|
2015-05-11 19:19:36 +00:00
|
|
|
continue;
|
|
|
|
count++;
|
2009-09-27 21:33:44 +00:00
|
|
|
}
|
|
|
|
//printf("count %d\n", count);
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal) {
|
2010-09-18 18:06:29 +00:00
|
|
|
int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
|
|
|
|
// here icons_per_column always higher than 0
|
2010-09-18 22:00:16 +00:00
|
|
|
sysbar->icons_per_column = (height+sysbar->area.paddingx) / (sysbar->icon_size+sysbar->area.paddingx);
|
|
|
|
sysbar->marging = height - (sysbar->icons_per_column-1)*(sysbar->icon_size+sysbar->area.paddingx) - sysbar->icon_size;
|
|
|
|
sysbar->icons_per_row = count / sysbar->icons_per_column + (count%sysbar->icons_per_column != 0);
|
|
|
|
systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (sysbar->icon_size * sysbar->icons_per_row) + ((sysbar->icons_per_row-1) * systray.area.paddingx);
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2010-09-18 18:06:29 +00:00
|
|
|
int width = sysbar->area.width - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
|
|
|
|
// here icons_per_row always higher than 0
|
2010-09-18 22:00:16 +00:00
|
|
|
sysbar->icons_per_row = (width+sysbar->area.paddingx) / (sysbar->icon_size+sysbar->area.paddingx);
|
|
|
|
sysbar->marging = width - (sysbar->icons_per_row-1)*(sysbar->icon_size+sysbar->area.paddingx) - sysbar->icon_size;
|
|
|
|
sysbar->icons_per_column = count / sysbar->icons_per_row+ (count%sysbar->icons_per_row != 0);
|
|
|
|
systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (sysbar->icon_size * sysbar->icons_per_column) + ((sysbar->icons_per_column-1) * systray.area.paddingx);
|
2009-06-19 21:08:34 +00:00
|
|
|
}
|
2010-09-16 23:24:25 +00:00
|
|
|
return 1;
|
2009-02-28 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2009-04-01 20:19:09 +00:00
|
|
|
|
2010-09-25 21:18:47 +00:00
|
|
|
void on_change_systray (void *obj)
|
|
|
|
{
|
2010-11-07 17:43:14 +00:00
|
|
|
// here, systray.area.posx/posy are defined by rendering engine. so we can calculate position of tray icon.
|
2010-09-25 21:18:47 +00:00
|
|
|
Systraybar *sysbar = obj;
|
2015-01-22 17:31:56 +00:00
|
|
|
if (sysbar->icons_per_column == 0 || sysbar->icons_per_row == 0)
|
|
|
|
return;
|
|
|
|
|
2010-11-09 19:32:45 +00:00
|
|
|
Panel *panel = sysbar->area.panel;
|
2010-09-25 21:18:47 +00:00
|
|
|
int i, posx, posy;
|
2010-11-09 19:32:45 +00:00
|
|
|
int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy + sysbar->marging/2;
|
2010-09-25 21:18:47 +00:00
|
|
|
if (panel_horizontal) {
|
|
|
|
posy = start;
|
|
|
|
posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2010-09-25 21:18:47 +00:00
|
|
|
posx = start;
|
|
|
|
posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrayWindow *traywin;
|
|
|
|
GSList *l;
|
2015-06-07 10:58:29 +00:00
|
|
|
for (i = 1, l = systray.list_icons; l ; i++, l = l->next) {
|
2010-09-25 21:18:47 +00:00
|
|
|
traywin = (TrayWindow*)l->data;
|
2015-05-11 19:19:36 +00:00
|
|
|
if (traywin->hide)
|
|
|
|
continue;
|
2010-09-25 21:18:47 +00:00
|
|
|
|
|
|
|
traywin->y = posy;
|
|
|
|
traywin->x = posx;
|
2015-06-07 10:58:29 +00:00
|
|
|
// printf("systray %d %d : pos %d, %d\n", traywin->parent, traywin->win, posx, posy);
|
2010-09-25 21:18:47 +00:00
|
|
|
traywin->width = sysbar->icon_size;
|
|
|
|
traywin->height = sysbar->icon_size;
|
|
|
|
if (panel_horizontal) {
|
2015-06-07 10:58:29 +00:00
|
|
|
if (i % sysbar->icons_per_column) {
|
2010-09-25 21:18:47 +00:00
|
|
|
posy += sysbar->icon_size + sysbar->area.paddingx;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2010-09-25 21:18:47 +00:00
|
|
|
posy = start;
|
|
|
|
posx += (sysbar->icon_size + systray.area.paddingx);
|
|
|
|
}
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
|
|
|
if (i % sysbar->icons_per_row) {
|
2010-09-25 21:18:47 +00:00
|
|
|
posx += sysbar->icon_size + systray.area.paddingx;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2010-09-25 21:18:47 +00:00
|
|
|
posx = start;
|
|
|
|
posy += (sysbar->icon_size + systray.area.paddingx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// position and size the icon window
|
2015-06-07 10:58:29 +00:00
|
|
|
XMoveResizeWindow(server.dsp, traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height);
|
2015-06-12 00:09:43 +00:00
|
|
|
if (traywin->reparented) {
|
|
|
|
XMoveResizeWindow(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height);
|
|
|
|
}
|
2010-09-25 21:18:47 +00:00
|
|
|
}
|
2015-06-07 09:44:43 +00:00
|
|
|
refresh_systray = 1;
|
2010-09-25 21:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-29 18:39:44 +00:00
|
|
|
// ***********************************************
|
|
|
|
// systray protocol
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-10-30 17:18:44 +00:00
|
|
|
void start_net()
|
2009-02-25 20:04:43 +00:00
|
|
|
{
|
2009-10-30 17:18:44 +00:00
|
|
|
if (net_sel_win) {
|
|
|
|
// protocol already started
|
|
|
|
if (!systray_enabled)
|
|
|
|
stop_net();
|
|
|
|
return;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2009-10-30 17:18:44 +00:00
|
|
|
if (!systray_enabled)
|
|
|
|
return;
|
2015-06-07 10:58:29 +00:00
|
|
|
}
|
2009-10-30 17:18:44 +00:00
|
|
|
|
2009-08-30 16:20:44 +00:00
|
|
|
Window win = XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN);
|
|
|
|
|
2009-06-29 18:39:44 +00:00
|
|
|
// freedesktop systray specification
|
2009-08-30 16:20:44 +00:00
|
|
|
if (win != None) {
|
|
|
|
// search pid
|
|
|
|
Atom _NET_WM_PID, actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes_after;
|
2009-09-25 19:11:50 +00:00
|
|
|
unsigned char *prop = 0;
|
2009-08-30 16:20:44 +00:00
|
|
|
int pid;
|
|
|
|
|
|
|
|
_NET_WM_PID = XInternAtom(server.dsp, "_NET_WM_PID", True);
|
|
|
|
int ret = XGetWindowProperty(server.dsp, win, _NET_WM_PID, 0, 1024, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop);
|
|
|
|
|
|
|
|
fprintf(stderr, "tint2 : another systray is running");
|
2009-09-25 19:11:50 +00:00
|
|
|
if (ret == Success && prop) {
|
2009-08-30 16:20:44 +00:00
|
|
|
pid = prop[1] * 256;
|
|
|
|
pid += prop[0];
|
|
|
|
fprintf(stderr, " pid=%d", pid);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2009-10-30 17:18:44 +00:00
|
|
|
return;
|
2009-03-07 10:05:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 20:04:43 +00:00
|
|
|
// init systray protocol
|
2009-09-07 21:41:21 +00:00
|
|
|
net_sel_win = XCreateSimpleWindow(server.dsp, server.root_win, -1, -1, 1, 1, 0, 0, 0);
|
2009-02-25 20:04:43 +00:00
|
|
|
|
2010-01-07 21:23:15 +00:00
|
|
|
// v0.3 trayer specification. tint2 always horizontal.
|
2009-09-27 21:33:44 +00:00
|
|
|
// Vertical panel will draw the systray horizontal.
|
2010-09-12 22:00:00 +00:00
|
|
|
long orient = 0;
|
2009-02-25 20:04:43 +00:00
|
|
|
XChangeProperty(server.dsp, net_sel_win, server.atom._NET_SYSTEM_TRAY_ORIENTATION, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &orient, 1);
|
2010-02-28 07:58:50 +00:00
|
|
|
VisualID vid;
|
2015-06-07 09:44:43 +00:00
|
|
|
if (systray_composited)
|
2010-02-28 07:58:50 +00:00
|
|
|
vid = XVisualIDFromVisual(server.visual32);
|
|
|
|
else
|
|
|
|
vid = XVisualIDFromVisual(server.visual);
|
2009-12-30 23:27:31 +00:00
|
|
|
XChangeProperty(server.dsp, net_sel_win, XInternAtom(server.dsp, "_NET_SYSTEM_TRAY_VISUAL", False), XA_VISUALID, 32, PropModeReplace, (unsigned char*)&vid, 1);
|
2009-02-25 20:04:43 +00:00
|
|
|
|
|
|
|
XSetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN, net_sel_win, CurrentTime);
|
|
|
|
if (XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN) != net_sel_win) {
|
2009-10-30 17:18:44 +00:00
|
|
|
stop_net();
|
2009-02-25 20:04:43 +00:00
|
|
|
fprintf(stderr, "tint2 : can't get systray manager\n");
|
2009-10-30 17:18:44 +00:00
|
|
|
return;
|
2009-09-07 21:41:21 +00:00
|
|
|
}
|
2009-02-25 20:04:43 +00:00
|
|
|
|
2009-10-30 17:18:44 +00:00
|
|
|
//fprintf(stderr, "tint2 : systray started\n");
|
2009-09-07 21:41:21 +00:00
|
|
|
XClientMessageEvent ev;
|
2009-02-25 20:04:43 +00:00
|
|
|
ev.type = ClientMessage;
|
2009-09-07 21:41:21 +00:00
|
|
|
ev.window = server.root_win;
|
2009-02-25 20:04:43 +00:00
|
|
|
ev.message_type = server.atom.MANAGER;
|
|
|
|
ev.format = 32;
|
|
|
|
ev.data.l[0] = CurrentTime;
|
|
|
|
ev.data.l[1] = server.atom._NET_SYSTEM_TRAY_SCREEN;
|
|
|
|
ev.data.l[2] = net_sel_win;
|
|
|
|
ev.data.l[3] = 0;
|
|
|
|
ev.data.l[4] = 0;
|
2009-02-27 22:18:30 +00:00
|
|
|
XSendEvent(server.dsp, server.root_win, False, StructureNotifyMask, (XEvent*)&ev);
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-30 17:18:44 +00:00
|
|
|
void stop_net()
|
2009-03-07 10:05:15 +00:00
|
|
|
{
|
2009-10-30 17:18:44 +00:00
|
|
|
//fprintf(stderr, "tint2 : systray stopped\n");
|
|
|
|
if (systray.list_icons) {
|
|
|
|
// remove_icon change systray.list_icons
|
|
|
|
while(systray.list_icons)
|
|
|
|
remove_icon((TrayWindow*)systray.list_icons->data);
|
|
|
|
|
|
|
|
g_slist_free(systray.list_icons);
|
2015-04-11 09:51:10 +00:00
|
|
|
systray.list_icons = NULL;
|
2009-10-30 17:18:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-07 10:05:15 +00:00
|
|
|
if (net_sel_win != None) {
|
2009-09-07 21:41:21 +00:00
|
|
|
XDestroyWindow(server.dsp, net_sel_win);
|
|
|
|
net_sel_win = None;
|
2009-03-07 10:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2009-04-01 20:19:09 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
gboolean error;
|
|
|
|
int window_error_handler(Display *d, XErrorEvent *e)
|
|
|
|
{
|
2009-06-18 20:26:40 +00:00
|
|
|
error = TRUE;
|
|
|
|
if (e->error_code != BadWindow) {
|
2015-06-11 23:43:39 +00:00
|
|
|
printf("systray: error code %d\n", e->error_code);
|
2009-06-18 20:26:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-29 22:09:29 +00:00
|
|
|
static gint compare_traywindows(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const TrayWindow * traywin_a = (TrayWindow*)a;
|
|
|
|
const TrayWindow * traywin_b = (TrayWindow*)b;
|
2015-05-11 19:19:36 +00:00
|
|
|
|
|
|
|
if (traywin_a->empty && !traywin_b->empty)
|
2015-05-30 11:33:44 +00:00
|
|
|
return 1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1);
|
2015-05-11 19:19:36 +00:00
|
|
|
if (!traywin_a->empty && traywin_b->empty)
|
2015-05-30 11:33:44 +00:00
|
|
|
return -1 * (systray.sort == SYSTRAY_SORT_RIGHT2LEFT ? -1 : 1);
|
2015-05-11 19:19:36 +00:00
|
|
|
|
2015-05-13 19:17:02 +00:00
|
|
|
if (systray.sort == SYSTRAY_SORT_ASCENDING ||
|
|
|
|
systray.sort == SYSTRAY_SORT_DESCENDING) {
|
|
|
|
XTextProperty name_a, name_b;
|
2009-08-29 22:09:29 +00:00
|
|
|
|
2015-06-07 10:58:29 +00:00
|
|
|
if (XGetWMName(server.dsp, traywin_a->win, &name_a) == 0) {
|
2015-05-13 19:17:02 +00:00
|
|
|
return -1;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else if (XGetWMName(server.dsp, traywin_b->win, &name_b) == 0) {
|
2015-05-13 19:17:02 +00:00
|
|
|
XFree(name_a.value);
|
|
|
|
return 1;
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2015-05-13 19:17:02 +00:00
|
|
|
gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) *
|
|
|
|
(systray.sort == SYSTRAY_SORT_ASCENDING ? 1 : -1);
|
|
|
|
XFree(name_a.value);
|
|
|
|
XFree(name_b.value);
|
|
|
|
return retval;
|
|
|
|
}
|
2009-08-29 22:09:29 +00:00
|
|
|
}
|
2015-05-13 19:17:02 +00:00
|
|
|
|
|
|
|
if (systray.sort == SYSTRAY_SORT_LEFT2RIGHT ||
|
|
|
|
systray.sort == SYSTRAY_SORT_RIGHT2LEFT) {
|
|
|
|
return (traywin_a->chrono - traywin_b->chrono) *
|
|
|
|
(systray.sort == SYSTRAY_SORT_LEFT2RIGHT ? 1 : -1);
|
2009-08-29 22:09:29 +00:00
|
|
|
}
|
2015-05-13 19:17:02 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-08-29 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-07 10:58:29 +00:00
|
|
|
gboolean add_icon(Window win)
|
2009-02-10 23:16:10 +00:00
|
|
|
{
|
2009-06-19 21:08:34 +00:00
|
|
|
TrayWindow *traywin;
|
2009-06-18 20:26:40 +00:00
|
|
|
Panel *panel = systray.area.panel;
|
2009-09-27 21:33:44 +00:00
|
|
|
int hide = 0;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Get the process ID of the application that created the window
|
2015-05-11 19:19:36 +00:00
|
|
|
int pid = 0;
|
|
|
|
{
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes_after;
|
|
|
|
unsigned char *prop = 0;
|
2015-06-07 10:58:29 +00:00
|
|
|
int ret = XGetWindowProperty(server.dsp, win, server.atom._NET_WM_PID, 0, 1024, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop);
|
2015-05-11 19:19:36 +00:00
|
|
|
if (ret == Success && prop) {
|
|
|
|
pid = prop[1] * 256;
|
|
|
|
pid += prop[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Check if the application leaves behind empty icons
|
2015-02-04 23:15:57 +00:00
|
|
|
GSList *l;
|
2015-05-11 19:19:36 +00:00
|
|
|
int num_empty_same_pid = 0;
|
2015-02-04 23:15:57 +00:00
|
|
|
for (l = systray.list_icons; l; l = l->next) {
|
2015-06-07 10:58:29 +00:00
|
|
|
if (((TrayWindow*)l->data)->win == win)
|
2015-02-04 23:15:57 +00:00
|
|
|
return FALSE;
|
2015-05-11 19:19:36 +00:00
|
|
|
if (pid && ((TrayWindow*)l->data)->pid == pid && ((TrayWindow*)l->data)->empty)
|
|
|
|
num_empty_same_pid++;
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Remove empty icons if the application leaves behind more than 1
|
2015-05-11 19:19:36 +00:00
|
|
|
const int max_num_empty_same_pid = 0;
|
|
|
|
if (num_empty_same_pid > max_num_empty_same_pid) {
|
|
|
|
for (l = systray.list_icons; l; l = l->next) {
|
|
|
|
if (pid && ((TrayWindow*)l->data)->pid == pid && ((TrayWindow*)l->data)->empty) {
|
|
|
|
num_empty_same_pid++;
|
2015-06-07 10:58:29 +00:00
|
|
|
fprintf(stderr, "Removing tray icon %lu from misbehaving application with pid=%d\n", ((TrayWindow*)l->data)->win, pid);
|
2015-05-11 19:19:36 +00:00
|
|
|
remove_icon((TrayWindow*)l->data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 23:15:57 +00:00
|
|
|
}
|
2015-06-07 10:58:29 +00:00
|
|
|
//printf("add_icon: %d, pid %d, %d\n", win, pid, num_empty_same_pid);
|
2015-02-04 23:15:57 +00:00
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Create the parent window that will embed the icon
|
2009-12-31 14:20:32 +00:00
|
|
|
XWindowAttributes attr;
|
2015-06-07 10:58:29 +00:00
|
|
|
if (XGetWindowAttributes(server.dsp, win, &attr) == False)
|
2015-06-07 10:45:48 +00:00
|
|
|
return FALSE;
|
2010-01-03 20:17:46 +00:00
|
|
|
unsigned long mask = 0;
|
2010-01-03 00:33:07 +00:00
|
|
|
XSetWindowAttributes set_attr;
|
2010-08-18 12:32:08 +00:00
|
|
|
Visual* visual = server.visual;
|
2010-04-22 15:08:21 +00:00
|
|
|
//printf("icon with depth: %d, width %d, height %d\n", attr.depth, attr.width, attr.height);
|
2015-06-07 09:44:43 +00:00
|
|
|
if (systray_composited || attr.depth != server.depth) {
|
2010-08-18 12:32:08 +00:00
|
|
|
visual = attr.visual;
|
2010-01-03 20:17:46 +00:00
|
|
|
set_attr.colormap = attr.colormap;
|
|
|
|
set_attr.background_pixel = 0;
|
|
|
|
set_attr.border_pixel = 0;
|
|
|
|
mask = CWColormap|CWBackPixel|CWBorderPixel;
|
2015-06-07 10:45:48 +00:00
|
|
|
} else {
|
2010-01-03 20:17:46 +00:00
|
|
|
set_attr.background_pixmap = ParentRelative;
|
|
|
|
mask = CWBackPixmap;
|
|
|
|
}
|
2015-06-07 10:58:29 +00:00
|
|
|
Window parent = XCreateWindow(server.dsp, panel->main_win, 0, 0, 30, 30, 0, attr.depth, InputOutput, visual, mask, &set_attr);
|
2015-06-07 10:45:48 +00:00
|
|
|
|
|
|
|
// Add the icon to the list
|
2009-02-25 20:04:43 +00:00
|
|
|
traywin = g_new0(TrayWindow, 1);
|
2015-06-07 10:58:29 +00:00
|
|
|
traywin->parent = parent;
|
|
|
|
traywin->win = win;
|
2009-09-27 21:33:44 +00:00
|
|
|
traywin->hide = hide;
|
2010-01-03 20:17:46 +00:00
|
|
|
traywin->depth = attr.depth;
|
2015-06-07 10:45:48 +00:00
|
|
|
// Reparenting is done at the first paint event when the window is positioned correctly over its empty background,
|
|
|
|
// to prevent graphical corruptions in icons with fake transparency
|
|
|
|
traywin->reparented = 0;
|
2010-01-03 20:17:46 +00:00
|
|
|
traywin->damage = 0;
|
2015-05-11 19:19:36 +00:00
|
|
|
traywin->empty = 0;
|
|
|
|
traywin->pid = pid;
|
2015-05-13 19:17:02 +00:00
|
|
|
traywin->chrono = chrono;
|
|
|
|
chrono++;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2010-09-18 18:06:29 +00:00
|
|
|
if (systray.area.on_screen == 0)
|
2010-09-22 19:33:10 +00:00
|
|
|
show(&systray.area);
|
2010-09-18 18:06:29 +00:00
|
|
|
|
2015-05-13 19:17:02 +00:00
|
|
|
if (systray.sort == SYSTRAY_SORT_RIGHT2LEFT)
|
2009-09-27 19:52:25 +00:00
|
|
|
systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
|
|
|
|
else
|
2015-05-13 19:02:40 +00:00
|
|
|
systray.list_icons = g_slist_append(systray.list_icons, traywin);
|
|
|
|
systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows);
|
2015-06-07 10:58:29 +00:00
|
|
|
// printf("add_icon win %lx, %d\n", win, g_slist_length(systray.list_icons));
|
2015-06-07 10:45:48 +00:00
|
|
|
|
2015-06-14 08:51:30 +00:00
|
|
|
if (!traywin->hide && !panel->is_hidden)
|
|
|
|
XMapRaised(server.dsp, traywin->parent);
|
|
|
|
XSync(server.dsp, False);
|
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Resize and redraw the systray
|
|
|
|
systray.area.resize = 1;
|
2015-06-12 00:09:43 +00:00
|
|
|
systray.area.redraw = 1;
|
2015-06-12 09:57:05 +00:00
|
|
|
panel->area.resize = 1;
|
2015-06-07 10:45:48 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean reparent_icon(TrayWindow *traywin)
|
|
|
|
{
|
|
|
|
if (traywin->reparented)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
Panel* panel = systray.area.panel;
|
|
|
|
|
2015-06-11 23:43:39 +00:00
|
|
|
// Reparent
|
2015-06-12 09:39:36 +00:00
|
|
|
XSync(server.dsp, False);
|
2015-06-07 10:58:29 +00:00
|
|
|
error = FALSE;
|
2015-06-07 10:45:48 +00:00
|
|
|
XErrorHandler old = XSetErrorHandler(window_error_handler);
|
2015-06-07 10:58:29 +00:00
|
|
|
XReparentWindow(server.dsp, traywin->win, traywin->parent, 0, 0);
|
2015-06-07 10:45:48 +00:00
|
|
|
XSync(server.dsp, False);
|
2015-06-11 23:43:39 +00:00
|
|
|
XSetErrorHandler(old);
|
|
|
|
if (error != FALSE) {
|
2015-06-12 00:09:43 +00:00
|
|
|
printf("systray %d: cannot embed icon for window %lu parent %lu pid %d\n", __LINE__, traywin->win, traywin->parent, traywin->pid);
|
2015-06-11 23:43:39 +00:00
|
|
|
remove_icon(traywin);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-06-07 10:45:48 +00:00
|
|
|
|
2015-06-12 09:57:05 +00:00
|
|
|
// Watch for the icon trying to resize itself / closing again
|
|
|
|
XSync(server.dsp, False);
|
|
|
|
error = FALSE;
|
|
|
|
old = XSetErrorHandler(window_error_handler);
|
|
|
|
XSelectInput(server.dsp, traywin->win, StructureNotifyMask);
|
|
|
|
XSync(server.dsp, False);
|
|
|
|
XSetErrorHandler(old);
|
|
|
|
if (error != FALSE) {
|
|
|
|
printf("systray %d: cannot embed icon for window %lu parent %lu pid %d\n", __LINE__, traywin->win, traywin->parent, traywin->pid);
|
|
|
|
remove_icon(traywin);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-06-12 07:44:13 +00:00
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
traywin->reparented = 1;
|
|
|
|
|
|
|
|
// Embed into parent
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
e.xclient.type = ClientMessage;
|
|
|
|
e.xclient.serial = 0;
|
|
|
|
e.xclient.send_event = True;
|
|
|
|
e.xclient.message_type = server.atom._XEMBED;
|
2015-06-12 09:40:22 +00:00
|
|
|
e.xclient.window = traywin->win;
|
2015-06-07 10:45:48 +00:00
|
|
|
e.xclient.format = 32;
|
|
|
|
e.xclient.data.l[0] = CurrentTime;
|
|
|
|
e.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY;
|
|
|
|
e.xclient.data.l[2] = 0;
|
2015-06-07 10:58:29 +00:00
|
|
|
e.xclient.data.l[3] = traywin->parent;
|
2015-06-07 10:45:48 +00:00
|
|
|
e.xclient.data.l[4] = 0;
|
2015-06-12 09:39:36 +00:00
|
|
|
XSync(server.dsp, False);
|
2015-06-11 23:43:39 +00:00
|
|
|
error = FALSE;
|
|
|
|
XErrorHandler old = XSetErrorHandler(window_error_handler);
|
2015-06-07 10:58:29 +00:00
|
|
|
XSendEvent(server.dsp, traywin->win, False, 0xFFFFFF, &e);
|
2015-06-07 10:45:48 +00:00
|
|
|
XSync(server.dsp, False);
|
2015-06-11 23:43:39 +00:00
|
|
|
XSetErrorHandler(old);
|
|
|
|
if (error != FALSE) {
|
|
|
|
printf("systray %d: cannot embed icon for window %lu pid %d\n", __LINE__, traywin->win, traywin->pid);
|
|
|
|
remove_icon(traywin);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-06-07 10:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if window was embedded
|
|
|
|
{
|
|
|
|
Atom acttype;
|
|
|
|
int actfmt;
|
|
|
|
unsigned long nbitem, bytes;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
int ret;
|
|
|
|
|
2015-06-07 10:58:29 +00:00
|
|
|
ret = XGetWindowProperty(server.dsp, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data);
|
2015-06-07 10:45:48 +00:00
|
|
|
if (ret == Success) {
|
|
|
|
if (data) {
|
|
|
|
if (nbitem == 2) {
|
2015-06-14 08:51:30 +00:00
|
|
|
int hide = ((data[1] & XEMBED_MAPPED) == 0);
|
|
|
|
if (hide) {
|
|
|
|
//fprintf(stderr, "tint2: window refused embedding\n");
|
|
|
|
//remove_icon(traywin);
|
|
|
|
//XFree(data);
|
|
|
|
//return FALSE;
|
|
|
|
}
|
2015-06-07 10:45:48 +00:00
|
|
|
}
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "tint2 : xembed error\n");
|
|
|
|
remove_icon(traywin);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect rendering when using compositing
|
2015-06-07 09:44:43 +00:00
|
|
|
if (systray_composited) {
|
2015-06-07 10:58:29 +00:00
|
|
|
traywin->damage = XDamageCreate(server.dsp, traywin->parent, XDamageReportRawRectangles);
|
|
|
|
XCompositeRedirectWindow(server.dsp, traywin->parent, CompositeRedirectManual);
|
2015-04-13 20:18:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
// Make the icon visible
|
2010-01-17 20:02:56 +00:00
|
|
|
if (!traywin->hide)
|
2015-06-07 10:58:29 +00:00
|
|
|
XMapWindow(server.dsp, traywin->win);
|
2015-04-13 20:18:28 +00:00
|
|
|
if (!traywin->hide && !panel->is_hidden)
|
2015-06-07 10:58:29 +00:00
|
|
|
XMapRaised(server.dsp, traywin->parent);
|
2009-02-27 22:18:30 +00:00
|
|
|
|
2015-06-12 09:57:05 +00:00
|
|
|
XMoveResizeWindow(server.dsp, traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height);
|
|
|
|
XMoveResizeWindow(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height);
|
|
|
|
|
2015-06-14 08:51:30 +00:00
|
|
|
XSync(server.dsp, False);
|
2015-06-12 09:57:05 +00:00
|
|
|
|
2009-02-25 20:04:43 +00:00
|
|
|
return TRUE;
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
|
|
|
|
2009-03-01 19:18:35 +00:00
|
|
|
void remove_icon(TrayWindow *traywin)
|
2009-02-27 22:18:30 +00:00
|
|
|
{
|
2009-06-29 18:39:44 +00:00
|
|
|
// remove from our list
|
|
|
|
systray.list_icons = g_slist_remove(systray.list_icons, traywin);
|
2015-06-12 00:09:43 +00:00
|
|
|
printf("remove_icon: %lu\n", traywin->win);
|
2009-06-29 18:39:44 +00:00
|
|
|
|
2015-06-07 10:58:29 +00:00
|
|
|
XSelectInput(server.dsp, traywin->win, NoEventMask);
|
2010-01-03 20:17:46 +00:00
|
|
|
if (traywin->damage)
|
|
|
|
XDamageDestroy(server.dsp, traywin->damage);
|
2009-02-27 22:18:30 +00:00
|
|
|
|
2009-03-01 19:18:35 +00:00
|
|
|
// reparent to root
|
2015-06-12 09:39:36 +00:00
|
|
|
XSync(server.dsp, False);
|
2009-03-01 19:18:35 +00:00
|
|
|
error = FALSE;
|
2015-06-12 10:24:19 +00:00
|
|
|
XErrorHandler old = XSetErrorHandler(window_error_handler);
|
2009-09-27 21:33:44 +00:00
|
|
|
if (!traywin->hide)
|
2015-06-07 10:58:29 +00:00
|
|
|
XUnmapWindow(server.dsp, traywin->win);
|
|
|
|
XReparentWindow(server.dsp, traywin->win, server.root_win, 0, 0);
|
|
|
|
XDestroyWindow(server.dsp, traywin->parent);
|
2009-03-01 19:18:35 +00:00
|
|
|
XSync(server.dsp, False);
|
|
|
|
XSetErrorHandler(old);
|
2015-04-17 20:17:25 +00:00
|
|
|
stop_timeout(traywin->render_timeout);
|
2009-10-30 20:54:29 +00:00
|
|
|
g_free(traywin);
|
2009-03-01 19:18:35 +00:00
|
|
|
|
2010-09-18 18:06:29 +00:00
|
|
|
// check empty systray
|
|
|
|
int count = 0;
|
|
|
|
GSList *l;
|
2015-04-11 09:51:10 +00:00
|
|
|
for (l = systray.list_icons; l; l = l->next) {
|
2015-05-13 20:58:58 +00:00
|
|
|
if (((TrayWindow*)l->data)->hide)
|
2015-05-11 19:19:36 +00:00
|
|
|
continue;
|
|
|
|
count++;
|
2010-09-18 18:06:29 +00:00
|
|
|
}
|
2010-09-22 19:33:10 +00:00
|
|
|
if (count == 0)
|
|
|
|
hide(&systray.area);
|
2015-06-07 09:44:43 +00:00
|
|
|
|
2010-09-21 09:54:19 +00:00
|
|
|
// changed in systray
|
|
|
|
systray.area.resize = 1;
|
2009-02-27 22:18:30 +00:00
|
|
|
panel_refresh = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
void net_message(XClientMessageEvent *e)
|
|
|
|
{
|
2009-02-25 20:04:43 +00:00
|
|
|
unsigned long opcode;
|
2015-06-07 10:58:29 +00:00
|
|
|
Window win;
|
2009-02-25 20:04:43 +00:00
|
|
|
|
|
|
|
opcode = e->data.l[1];
|
|
|
|
switch (opcode) {
|
2015-06-07 09:44:43 +00:00
|
|
|
case SYSTEM_TRAY_REQUEST_DOCK:
|
2015-06-07 10:58:29 +00:00
|
|
|
win = e->data.l[2];
|
|
|
|
if (win)
|
|
|
|
add_icon(win);
|
2015-06-07 09:44:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SYSTEM_TRAY_BEGIN_MESSAGE:
|
|
|
|
case SYSTEM_TRAY_CANCEL_MESSAGE:
|
|
|
|
// we don't show baloons messages.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (opcode == server.atom._NET_SYSTEM_TRAY_MESSAGE_DATA)
|
|
|
|
printf("message from dockapp: %s\n", e->data.b);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "SYSTEM_TRAY : unknown message type\n");
|
|
|
|
break;
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 10:45:48 +00:00
|
|
|
void systray_render_icon_composited(void* t)
|
2010-01-03 00:33:07 +00:00
|
|
|
{
|
2010-02-20 10:08:56 +00:00
|
|
|
// we end up in this function only in real transparency mode or if systray_task_asb != 100 0 0
|
2010-02-28 07:58:50 +00:00
|
|
|
// we made also sure, that we always have a 32 bit visual, i.e. we can safely create 32 bit pixmaps here
|
2010-01-07 19:51:00 +00:00
|
|
|
TrayWindow* traywin = t;
|
2015-05-11 19:19:36 +00:00
|
|
|
|
2015-06-07 09:44:43 +00:00
|
|
|
// wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms
|
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
struct timespec earliest_render = add_msec_to_timespec(traywin->time_last_render, 50);
|
|
|
|
if (compare_timespecs(&earliest_render, &now) > 0) {
|
2015-06-07 10:45:48 +00:00
|
|
|
traywin->render_timeout = add_timeout(50, 0, systray_render_icon_composited, traywin, &traywin->render_timeout);
|
2015-06-07 09:44:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
traywin->time_last_render.tv_sec = now.tv_sec;
|
|
|
|
traywin->time_last_render.tv_nsec = now.tv_nsec;
|
2015-05-30 11:41:29 +00:00
|
|
|
|
2015-06-14 08:51:30 +00:00
|
|
|
if (traywin->width == 0 || traywin->height == 0) {
|
2010-10-08 21:45:14 +00:00
|
|
|
// reschedule rendering since the geometry information has not yet been processed (can happen on slow cpu)
|
2015-06-07 10:45:48 +00:00
|
|
|
traywin->render_timeout = add_timeout(50, 0, systray_render_icon_composited, traywin, &traywin->render_timeout);
|
2010-10-08 21:45:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-06 19:47:12 +00:00
|
|
|
|
2015-06-07 09:44:43 +00:00
|
|
|
if (traywin->render_timeout) {
|
|
|
|
stop_timeout(traywin->render_timeout);
|
|
|
|
traywin->render_timeout = NULL;
|
|
|
|
}
|
2015-05-30 12:22:40 +00:00
|
|
|
|
2015-06-14 08:51:30 +00:00
|
|
|
{
|
|
|
|
unsigned int border_width;
|
|
|
|
int xpos, ypos;
|
|
|
|
unsigned int width, height, depth;
|
|
|
|
Window root;
|
|
|
|
if (!XGetGeometry(server.dsp, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) {
|
|
|
|
fprintf(stderr, "Couldn't get geometry of window!\n");
|
2015-06-12 19:13:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-14 08:51:30 +00:00
|
|
|
if (width != traywin->width || height != traywin->height) {
|
|
|
|
XMoveResizeWindow(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height);
|
|
|
|
traywin->render_timeout = add_timeout(50, 0, systray_render_icon_composited, traywin, &traywin->render_timeout);
|
|
|
|
return;
|
2015-05-11 19:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-03 20:17:46 +00:00
|
|
|
// good systray icons support 32 bit depth, but some icons are still 24 bit.
|
2010-01-03 00:33:07 +00:00
|
|
|
// We create a heuristic mask for these icons, i.e. we get the rgb value in the top left corner, and
|
|
|
|
// mask out all pixel with the same rgb value
|
|
|
|
Panel* panel = systray.area.panel;
|
2010-01-31 14:04:58 +00:00
|
|
|
|
|
|
|
// Very ugly hack, but somehow imlib2 is not able to get the image from the traywindow itself,
|
|
|
|
// so we first render the tray window onto a pixmap, and then we tell imlib2 to use this pixmap as
|
|
|
|
// drawable. If someone knows why it does not work with the traywindow itself, please tell me ;)
|
2015-06-12 19:13:20 +00:00
|
|
|
Pixmap tmp_pmap = XCreatePixmap(server.dsp, traywin->win, traywin->width, traywin->height, 32);
|
2015-06-12 10:24:19 +00:00
|
|
|
if (!tmp_pmap) {
|
2015-06-13 09:32:22 +00:00
|
|
|
goto on_systray_error;
|
2015-06-12 10:24:19 +00:00
|
|
|
}
|
|
|
|
XRenderPictFormat *f;
|
2015-06-07 10:58:29 +00:00
|
|
|
if (traywin->depth == 24) {
|
2010-01-31 16:56:54 +00:00
|
|
|
f = XRenderFindStandardFormat(server.dsp, PictStandardRGB24);
|
2015-06-07 10:58:29 +00:00
|
|
|
} else if (traywin->depth == 32) {
|
2010-01-31 15:10:38 +00:00
|
|
|
f = XRenderFindStandardFormat(server.dsp, PictStandardARGB32);
|
2015-06-07 10:58:29 +00:00
|
|
|
} else {
|
2010-02-20 10:08:56 +00:00
|
|
|
printf("Strange tray icon found with depth: %d\n", traywin->depth);
|
2015-06-12 19:13:20 +00:00
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
2010-01-31 16:56:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-12 10:24:19 +00:00
|
|
|
XRenderPictFormat *f32 = XRenderFindVisualFormat(server.dsp, server.visual32);
|
|
|
|
if (!f || !f32) {
|
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
2015-06-13 09:32:22 +00:00
|
|
|
goto on_systray_error;
|
2015-06-12 10:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XSync(server.dsp, False);
|
|
|
|
error = FALSE;
|
|
|
|
XErrorHandler old = XSetErrorHandler(window_error_handler);
|
|
|
|
|
2010-04-20 15:14:37 +00:00
|
|
|
//if (server.real_transparency)
|
2015-06-12 10:24:19 +00:00
|
|
|
//Picture pict_image = XRenderCreatePicture(server.dsp, traywin->parent, f, 0, 0);
|
2010-04-20 15:14:37 +00:00
|
|
|
// reverted Rev 407 because here it's breaking alls icon with systray + xcompmgr
|
2015-06-12 10:24:19 +00:00
|
|
|
Picture pict_image = XRenderCreatePicture(server.dsp, traywin->win, f, 0, 0);
|
|
|
|
if (!pict_image) {
|
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
|
|
|
XSetErrorHandler(old);
|
|
|
|
goto on_error;
|
|
|
|
}
|
2010-02-28 07:58:50 +00:00
|
|
|
Picture pict_drawable = XRenderCreatePicture(server.dsp, tmp_pmap, XRenderFindVisualFormat(server.dsp, server.visual32), 0, 0);
|
2015-06-12 10:24:19 +00:00
|
|
|
if (!pict_drawable) {
|
|
|
|
XRenderFreePicture(server.dsp, pict_image);
|
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
|
|
|
XSetErrorHandler(old);
|
|
|
|
goto on_error;
|
|
|
|
}
|
2010-01-31 14:04:58 +00:00
|
|
|
XRenderComposite(server.dsp, PictOpSrc, pict_image, None, pict_drawable, 0, 0, 0, 0, 0, 0, traywin->width, traywin->height);
|
|
|
|
XRenderFreePicture(server.dsp, pict_image);
|
|
|
|
XRenderFreePicture(server.dsp, pict_drawable);
|
|
|
|
// end of the ugly hack and we can continue as before
|
|
|
|
|
2010-02-28 07:58:50 +00:00
|
|
|
imlib_context_set_visual(server.visual32);
|
|
|
|
imlib_context_set_colormap(server.colormap32);
|
2010-01-31 14:04:58 +00:00
|
|
|
imlib_context_set_drawable(tmp_pmap);
|
|
|
|
Imlib_Image image = imlib_create_image_from_drawable(0, 0, 0, traywin->width, traywin->height, 1);
|
2015-06-12 10:24:19 +00:00
|
|
|
if (!image) {
|
|
|
|
imlib_context_set_visual(server.visual);
|
|
|
|
imlib_context_set_colormap(server.colormap);
|
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
|
|
|
XSetErrorHandler(old);
|
|
|
|
goto on_error;
|
|
|
|
}
|
2010-01-06 19:30:55 +00:00
|
|
|
|
2010-01-03 20:17:46 +00:00
|
|
|
imlib_context_set_image(image);
|
2010-04-22 15:08:21 +00:00
|
|
|
//if (traywin->depth == 24)
|
2015-06-07 09:44:43 +00:00
|
|
|
//imlib_save_image("/home/thil77/test.jpg");
|
2010-01-03 20:17:46 +00:00
|
|
|
imlib_image_set_has_alpha(1);
|
|
|
|
DATA32* data = imlib_image_get_data();
|
2010-02-28 07:58:50 +00:00
|
|
|
if (traywin->depth == 24) {
|
2010-01-03 00:33:07 +00:00
|
|
|
createHeuristicMask(data, traywin->width, traywin->height);
|
|
|
|
}
|
2015-06-14 08:51:30 +00:00
|
|
|
|
|
|
|
int empty = imageEmpty(data, traywin->width, traywin->height);
|
2010-01-03 20:17:46 +00:00
|
|
|
if (systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0)
|
|
|
|
adjust_asb(data, traywin->width, traywin->height, systray.alpha, (float)systray.saturation/100, (float)systray.brightness/100);
|
|
|
|
imlib_image_put_back_data(data);
|
2010-01-09 00:11:01 +00:00
|
|
|
XCopyArea(server.dsp, render_background, systray.area.pix, server.gc, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height, traywin->x-systray.area.posx, traywin->y-systray.area.posy);
|
2015-05-03 13:36:34 +00:00
|
|
|
render_image(systray.area.pix, traywin->x-systray.area.posx, traywin->y-systray.area.posy);
|
2010-01-09 00:11:01 +00:00
|
|
|
XCopyArea(server.dsp, systray.area.pix, panel->main_win, server.gc, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height, traywin->x, traywin->y);
|
2010-01-05 11:21:18 +00:00
|
|
|
imlib_free_image_and_decache();
|
2010-01-31 14:04:58 +00:00
|
|
|
XFreePixmap(server.dsp, tmp_pmap);
|
2010-02-28 07:58:50 +00:00
|
|
|
imlib_context_set_visual(server.visual);
|
|
|
|
imlib_context_set_colormap(server.colormap);
|
2010-01-06 19:47:12 +00:00
|
|
|
|
2010-01-26 18:32:00 +00:00
|
|
|
if (traywin->damage)
|
|
|
|
XDamageSubtract(server.dsp, traywin->damage, None, None);
|
2015-06-12 10:24:19 +00:00
|
|
|
XSync(server.dsp, False);
|
|
|
|
XSetErrorHandler(old);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
goto on_error;
|
|
|
|
|
2015-06-14 08:51:30 +00:00
|
|
|
if (traywin->empty != empty) {
|
|
|
|
traywin->empty = empty;
|
|
|
|
systray.area.resize = 1;
|
|
|
|
panel_refresh = 1;
|
|
|
|
systray.list_icons = g_slist_sort(systray.list_icons, compare_traywindows);
|
|
|
|
}
|
|
|
|
|
2015-06-12 10:24:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
on_error:
|
2015-06-13 09:32:22 +00:00
|
|
|
printf("systray %d: rendering error for icon %lu pid %d\n", __LINE__, traywin->win, traywin->pid);
|
|
|
|
return;
|
|
|
|
|
|
|
|
on_systray_error:
|
|
|
|
printf("systray %d: rendering error for icon %lu pid %d. Disabling compositing and restarting systray...\n", __LINE__, traywin->win, traywin->pid);
|
2015-06-12 10:24:19 +00:00
|
|
|
systray_composited = 0;
|
|
|
|
stop_net();
|
|
|
|
start_net();
|
|
|
|
return;
|
2010-01-06 19:47:12 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 21:23:15 +00:00
|
|
|
|
2010-01-06 19:47:12 +00:00
|
|
|
void systray_render_icon(TrayWindow* traywin)
|
|
|
|
{
|
2015-06-14 08:51:30 +00:00
|
|
|
if (!traywin->reparented) {
|
|
|
|
if (!reparent_icon(traywin))
|
|
|
|
return;
|
|
|
|
if (systray_composited) {
|
|
|
|
// We need to process the events in the main loop first
|
|
|
|
stop_timeout(traywin->render_timeout);
|
|
|
|
traywin->render_timeout = add_timeout(50, 0, systray_render_icon_composited, traywin, &traywin->render_timeout);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 10:45:48 +00:00
|
|
|
|
2015-06-07 09:44:43 +00:00
|
|
|
if (systray_composited) {
|
|
|
|
if (!traywin->render_timeout)
|
2015-06-07 10:45:48 +00:00
|
|
|
systray_render_icon_composited(traywin);
|
|
|
|
} else {
|
|
|
|
// Trigger window repaint
|
2015-06-07 10:58:29 +00:00
|
|
|
XClearArea(server.dsp, traywin->parent, 0, 0, traywin->width, traywin->height, True);
|
|
|
|
XClearArea(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height, True);
|
2010-01-30 23:06:07 +00:00
|
|
|
}
|
2010-01-03 00:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 15:08:33 +00:00
|
|
|
void refresh_systray_icon()
|
2009-06-13 19:39:41 +00:00
|
|
|
{
|
|
|
|
TrayWindow *traywin;
|
|
|
|
GSList *l;
|
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
|
|
|
traywin = (TrayWindow*)l->data;
|
2015-05-11 19:19:36 +00:00
|
|
|
if (traywin->hide)
|
|
|
|
continue;
|
2010-01-30 23:06:07 +00:00
|
|
|
systray_render_icon(traywin);
|
2009-06-13 19:39:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-31 11:02:35 +00:00
|
|
|
|
|
|
|
int systray_on_monitor(int i_monitor, int nb_panels)
|
|
|
|
{
|
|
|
|
return (i_monitor == systray_monitor) ||
|
|
|
|
(i_monitor == 0 && (systray_monitor >= nb_panels || systray_monitor < 0));
|
|
|
|
}
|