2009-01-20 21:16:54 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* Tint2 : systraybar
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 thierry lorthiois (lorthiois@bbsoft.fr)
|
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>
|
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
|
2009-04-01 20:19:09 +00:00
|
|
|
Window net_sel_win = None, hint_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-01-03 13:14:25 +00:00
|
|
|
int systray_max_icon_size = 0;
|
2009-02-27 22:18:30 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
|
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
|
|
|
start_net();
|
2009-02-15 17:22:48 +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
|
|
|
|
2009-06-20 15:08:33 +00:00
|
|
|
systray.area._draw_foreground = draw_systray;
|
2009-06-19 21:08:34 +00:00
|
|
|
systray.area._resize = resize_systray;
|
2009-06-24 20:17:57 +00:00
|
|
|
systray.area.resize = 1;
|
|
|
|
systray.area.redraw = 1;
|
2009-10-30 17:18:44 +00:00
|
|
|
systray.area.on_screen = 1;
|
2009-06-20 15:08:33 +00:00
|
|
|
refresh_systray = 0;
|
2009-10-18 17:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init_systray_panel(void *p)
|
|
|
|
{
|
|
|
|
Panel *panel =(Panel*)p;
|
2009-06-19 21:08:34 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal) {
|
|
|
|
systray.area.posy = panel->area.pix.border.width + panel->area.paddingy;
|
|
|
|
systray.area.height = panel->area.height - (2 * systray.area.posy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
systray.area.posx = panel->area.pix.border.width + panel->area.paddingy;
|
|
|
|
systray.area.width = panel->area.width - (2 * panel->area.pix.border.width) - (2 * panel->area.paddingy);
|
|
|
|
}
|
2009-10-18 17:54:09 +00:00
|
|
|
systray.area.parent = p;
|
|
|
|
systray.area.panel = p;
|
2009-02-15 17:22:48 +00:00
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
|
|
|
|
|
2009-02-15 17:22:48 +00:00
|
|
|
void cleanup_systray()
|
|
|
|
{
|
2009-10-30 17:18:44 +00:00
|
|
|
systray_enabled = 0;
|
|
|
|
systray.area.on_screen = 0;
|
2009-02-27 22:18:30 +00:00
|
|
|
free_area(&systray.area);
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 15:08:33 +00:00
|
|
|
void draw_systray(void *obj, cairo_t *c, int active)
|
|
|
|
{
|
|
|
|
// tint2 don't draw systray icons. just the background.
|
|
|
|
refresh_systray = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-28 23:04:53 +00:00
|
|
|
void resize_systray(void *obj)
|
|
|
|
{
|
|
|
|
Systraybar *sysbar = obj;
|
|
|
|
Panel *panel = sysbar->area.panel;
|
|
|
|
TrayWindow *traywin;
|
|
|
|
GSList *l;
|
|
|
|
int count, posx, posy;
|
|
|
|
int icon_size;
|
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal)
|
|
|
|
icon_size = sysbar->area.height;
|
|
|
|
else
|
|
|
|
icon_size = sysbar->area.width;
|
|
|
|
icon_size = icon_size - (2 * sysbar->area.pix.border.width) - (2 * sysbar->area.paddingy);
|
2010-01-03 13:14:25 +00:00
|
|
|
if (systray_max_icon_size > 0 && icon_size > systray_max_icon_size)
|
|
|
|
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) {
|
|
|
|
if (!((TrayWindow*)l->data)->hide)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
//printf("count %d\n", count);
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal) {
|
|
|
|
if (!count) systray.area.width = 0;
|
2010-01-03 13:14:25 +00:00
|
|
|
else {
|
|
|
|
int icons_per_column = (sysbar->area.height - 2*sysbar->area.pix.border.width - 2*sysbar->area.paddingy + sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
|
|
|
|
int row_count = count / icons_per_column + (count%icons_per_column != 0);
|
|
|
|
systray.area.width = (2 * systray.area.pix.border.width) + (2 * systray.area.paddingxlr) + (icon_size * row_count) + ((row_count-1) * systray.area.paddingx);
|
|
|
|
}
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
systray.area.posx = panel->area.width - panel->area.pix.border.width - panel->area.paddingxlr - systray.area.width;
|
|
|
|
if (panel->clock.area.on_screen)
|
|
|
|
systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
|
2009-06-18 20:26:40 +00:00
|
|
|
#ifdef ENABLE_BATTERY
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel->battery.area.on_screen)
|
|
|
|
systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
|
2009-06-18 20:26:40 +00:00
|
|
|
#endif
|
2009-06-24 20:17:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!count) systray.area.height = 0;
|
2010-01-03 13:14:25 +00:00
|
|
|
else {
|
|
|
|
int icons_per_row = (sysbar->area.width - 2*sysbar->area.pix.border.width - 2*sysbar->area.paddingy + sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
|
|
|
|
int column_count = count / icons_per_row+ (count%icons_per_row != 0);
|
|
|
|
systray.area.height = (2 * systray.area.pix.border.width) + (2 * systray.area.paddingxlr) + (icon_size * column_count) + ((column_count-1) * systray.area.paddingx);
|
|
|
|
}
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-24 20:17:57 +00:00
|
|
|
systray.area.posy = panel->area.pix.border.width + panel->area.paddingxlr;
|
|
|
|
if (panel->clock.area.on_screen)
|
|
|
|
systray.area.posy += (panel->clock.area.height + panel->area.paddingx);
|
|
|
|
#ifdef ENABLE_BATTERY
|
|
|
|
if (panel->battery.area.on_screen)
|
|
|
|
systray.area.posy += (panel->battery.area.height + panel->area.paddingx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-01-03 13:14:25 +00:00
|
|
|
int max_line_pos;
|
2009-06-24 20:17:57 +00:00
|
|
|
if (panel_horizontal) {
|
2010-01-03 13:14:25 +00:00
|
|
|
max_line_pos = sysbar->area.posy+sysbar->area.height - sysbar->area.pix.border.width - sysbar->area.paddingy - icon_size;
|
2009-06-24 20:17:57 +00:00
|
|
|
posy = panel->area.pix.border.width + panel->area.paddingy + systray.area.pix.border.width + systray.area.paddingy;
|
|
|
|
posx = systray.area.posx + systray.area.pix.border.width + systray.area.paddingxlr;
|
|
|
|
}
|
|
|
|
else {
|
2010-01-03 13:14:25 +00:00
|
|
|
max_line_pos = sysbar->area.posx+sysbar->area.width - sysbar->area.pix.border.width - sysbar->area.paddingy - icon_size;
|
2009-06-24 20:17:57 +00:00
|
|
|
posx = panel->area.pix.border.width + panel->area.paddingy + systray.area.pix.border.width + systray.area.paddingy;
|
|
|
|
posy = systray.area.posy + systray.area.pix.border.width + systray.area.paddingxlr;
|
|
|
|
}
|
2010-01-03 13:14:25 +00:00
|
|
|
|
2009-02-28 23:04:53 +00:00
|
|
|
for (l = systray.list_icons; l ; l = l->next) {
|
|
|
|
traywin = (TrayWindow*)l->data;
|
2009-09-27 21:33:44 +00:00
|
|
|
if (traywin->hide) continue;
|
2009-02-28 23:04:53 +00:00
|
|
|
|
|
|
|
traywin->y = posy;
|
|
|
|
traywin->x = posx;
|
2009-06-14 19:07:58 +00:00
|
|
|
traywin->width = icon_size;
|
|
|
|
traywin->height = icon_size;
|
2010-01-03 13:14:25 +00:00
|
|
|
if (panel_horizontal) {
|
|
|
|
if (posy + icon_size + sysbar->area.paddingxlr < max_line_pos)
|
|
|
|
posy += icon_size + sysbar->area.paddingx;
|
|
|
|
else {
|
|
|
|
posx += (icon_size + systray.area.paddingx);
|
|
|
|
posy = panel->area.pix.border.width + panel->area.paddingy + systray.area.pix.border.width + systray.area.paddingy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (posx + icon_size + sysbar->area.paddingxlr < max_line_pos)
|
|
|
|
posx += icon_size + systray.area.paddingx;
|
|
|
|
else {
|
|
|
|
posy += (icon_size + systray.area.paddingx);
|
|
|
|
posx = panel->area.pix.border.width + panel->area.paddingy + systray.area.pix.border.width + systray.area.paddingy;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 23:04:53 +00:00
|
|
|
|
2009-06-19 21:08:34 +00:00
|
|
|
// position and size the icon window
|
|
|
|
XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size);
|
2010-01-03 00:33:07 +00:00
|
|
|
XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size);
|
2009-06-19 21:08:34 +00:00
|
|
|
}
|
2009-02-28 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2009-04-01 20:19:09 +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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!systray_enabled)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2009-09-27 21:33:44 +00:00
|
|
|
// v0.2 trayer specification. tint2 always horizontal.
|
|
|
|
// Vertical panel will draw the systray horizontal.
|
2009-02-25 20:04:43 +00:00
|
|
|
int orient = 0;
|
|
|
|
XChangeProperty(server.dsp, net_sel_win, server.atom._NET_SYSTEM_TRAY_ORIENTATION, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &orient, 1);
|
2009-12-30 23:27:31 +00:00
|
|
|
VisualID vid = XVisualIDFromVisual(server.visual);
|
|
|
|
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);
|
|
|
|
systray.list_icons = 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
d=d;e=e;
|
|
|
|
error = TRUE;
|
|
|
|
if (e->error_code != BadWindow) {
|
|
|
|
printf("error_handler %d\n", e->error_code);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
XTextProperty name_a, name_b;
|
|
|
|
|
2010-01-03 00:33:07 +00:00
|
|
|
if(XGetWMName(server.dsp, traywin_a->tray_id, &name_a) == 0) {
|
2009-08-29 22:09:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-03 00:33:07 +00:00
|
|
|
else if(XGetWMName(server.dsp, traywin_b->tray_id, &name_b) == 0) {
|
2009-08-29 22:09:29 +00:00
|
|
|
XFree(name_a.value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gint retval = g_ascii_strncasecmp((char*)name_a.value, (char*)name_b.value, -1) * systray.sort;
|
|
|
|
XFree(name_a.value);
|
|
|
|
XFree(name_b.value);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-19 21:08:34 +00:00
|
|
|
gboolean add_icon(Window id)
|
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
|
|
|
XErrorHandler old;
|
|
|
|
Panel *panel = systray.area.panel;
|
2009-09-27 21:33:44 +00:00
|
|
|
int hide = 0;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2009-06-18 20:26:40 +00:00
|
|
|
error = FALSE;
|
2009-12-31 14:20:32 +00:00
|
|
|
XWindowAttributes attr;
|
|
|
|
XGetWindowAttributes(server.dsp, id, &attr);
|
2010-01-03 20:17:46 +00:00
|
|
|
unsigned long mask = 0;
|
2010-01-03 00:33:07 +00:00
|
|
|
XSetWindowAttributes set_attr;
|
2010-01-03 20:17:46 +00:00
|
|
|
if (attr.depth != server.depth || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0 ) {
|
|
|
|
set_attr.colormap = attr.colormap;
|
|
|
|
set_attr.background_pixel = 0;
|
|
|
|
set_attr.border_pixel = 0;
|
|
|
|
mask = CWColormap|CWBackPixel|CWBorderPixel;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_attr.background_pixmap = ParentRelative;
|
|
|
|
mask = CWBackPixmap;
|
|
|
|
}
|
2010-01-03 00:33:07 +00:00
|
|
|
Window parent_window;
|
2010-01-03 20:17:46 +00:00
|
|
|
parent_window = XCreateWindow(server.dsp, panel->main_win, 0, 0, 30, 30, 0, attr.depth, InputOutput, attr.visual, mask, &set_attr);
|
2010-01-03 13:14:25 +00:00
|
|
|
old = XSetErrorHandler(window_error_handler);
|
2010-01-03 00:33:07 +00:00
|
|
|
XReparentWindow(server.dsp, id, parent_window, 0, 0);
|
2009-06-18 20:26:40 +00:00
|
|
|
XSync(server.dsp, False);
|
|
|
|
XSetErrorHandler(old);
|
2009-06-19 21:08:34 +00:00
|
|
|
if (error != FALSE) {
|
2009-03-01 19:18:35 +00:00
|
|
|
fprintf(stderr, "tint2 : not icon_swallow\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-29 18:39:44 +00:00
|
|
|
{
|
|
|
|
Atom acttype;
|
|
|
|
int actfmt;
|
|
|
|
unsigned long nbitem, bytes;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = XGetWindowProperty(server.dsp, id, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data);
|
2009-09-27 21:33:44 +00:00
|
|
|
if (ret == Success) {
|
|
|
|
if (data) {
|
|
|
|
if (nbitem == 2) {
|
|
|
|
//hide = ((data[1] & XEMBED_MAPPED) == 0);
|
|
|
|
//printf("hide %d\n", hide);
|
|
|
|
}
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-06-29 18:39:44 +00:00
|
|
|
fprintf(stderr, "tint2 : xembed error\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
e.xclient.type = ClientMessage;
|
|
|
|
e.xclient.serial = 0;
|
|
|
|
e.xclient.send_event = True;
|
|
|
|
e.xclient.message_type = server.atom._XEMBED;
|
|
|
|
e.xclient.window = id;
|
|
|
|
e.xclient.format = 32;
|
|
|
|
e.xclient.data.l[0] = CurrentTime;
|
|
|
|
e.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY;
|
|
|
|
e.xclient.data.l[2] = 0;
|
2010-01-03 00:33:07 +00:00
|
|
|
e.xclient.data.l[3] = parent_window;
|
2009-06-29 18:39:44 +00:00
|
|
|
e.xclient.data.l[4] = 0;
|
|
|
|
XSendEvent(server.dsp, id, False, 0xFFFFFF, &e);
|
|
|
|
}
|
|
|
|
|
2009-02-25 20:04:43 +00:00
|
|
|
traywin = g_new0(TrayWindow, 1);
|
2010-01-03 20:17:46 +00:00
|
|
|
traywin->id = parent_window;
|
2010-01-03 00:33:07 +00:00
|
|
|
traywin->tray_id = id;
|
2009-09-27 21:33:44 +00:00
|
|
|
traywin->hide = hide;
|
2010-01-03 20:17:46 +00:00
|
|
|
traywin->depth = attr.depth;
|
|
|
|
traywin->damage = 0;
|
2009-02-10 23:16:10 +00:00
|
|
|
|
2009-09-27 20:00:34 +00:00
|
|
|
if (systray.sort == 3)
|
2009-09-27 19:52:25 +00:00
|
|
|
systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
|
2009-09-27 20:00:34 +00:00
|
|
|
else if (systray.sort == 2)
|
|
|
|
systray.list_icons = g_slist_append(systray.list_icons, traywin);
|
2009-09-27 19:52:25 +00:00
|
|
|
else
|
|
|
|
systray.list_icons = g_slist_insert_sorted(systray.list_icons, traywin, compare_traywindows);
|
2009-09-07 21:41:21 +00:00
|
|
|
systray.area.resize = 1;
|
2009-06-19 21:08:34 +00:00
|
|
|
systray.area.redraw = 1;
|
2009-06-29 18:39:44 +00:00
|
|
|
//printf("add_icon id %lx, %d\n", id, g_slist_length(systray.list_icons));
|
2009-06-19 21:08:34 +00:00
|
|
|
|
|
|
|
// watch for the icon trying to resize itself!
|
2010-01-03 00:33:07 +00:00
|
|
|
XSelectInput(server.dsp, traywin->tray_id, StructureNotifyMask);
|
2010-01-03 20:17:46 +00:00
|
|
|
if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
|
|
|
|
traywin->damage = XDamageCreate(server.dsp, traywin->id, XDamageReportRawRectangles);
|
2010-01-03 00:33:07 +00:00
|
|
|
XCompositeRedirectWindow(server.dsp, traywin->id, CompositeRedirectManual);
|
|
|
|
}
|
2009-06-19 21:08:34 +00:00
|
|
|
|
|
|
|
// show the window
|
2010-01-03 00:33:07 +00:00
|
|
|
if (!traywin->hide) {
|
|
|
|
XMapRaised(server.dsp, traywin->tray_id);
|
2010-01-03 20:17:46 +00:00
|
|
|
XMapRaised(server.dsp, traywin->id);
|
2010-01-03 00:33:07 +00:00
|
|
|
}
|
2009-02-27 22:18:30 +00:00
|
|
|
|
|
|
|
// changed in systray force resize on panel
|
|
|
|
panel->area.resize = 1;
|
|
|
|
panel_refresh = 1;
|
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
|
|
|
{
|
|
|
|
XErrorHandler old;
|
|
|
|
|
2009-06-29 18:39:44 +00:00
|
|
|
// remove from our list
|
|
|
|
systray.list_icons = g_slist_remove(systray.list_icons, traywin);
|
2009-09-07 21:41:21 +00:00
|
|
|
systray.area.resize = 1;
|
2009-06-29 18:39:44 +00:00
|
|
|
systray.area.redraw = 1;
|
|
|
|
//printf("remove_icon id %lx, %d\n", traywin->id);
|
|
|
|
|
2010-01-03 00:33:07 +00:00
|
|
|
XSelectInput(server.dsp, traywin->tray_id, 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
|
|
|
|
error = FALSE;
|
|
|
|
old = XSetErrorHandler(window_error_handler);
|
2009-09-27 21:33:44 +00:00
|
|
|
if (!traywin->hide)
|
|
|
|
XUnmapWindow(server.dsp, traywin->id);
|
2010-01-03 00:33:07 +00:00
|
|
|
XReparentWindow(server.dsp, traywin->tray_id, server.root_win, 0, 0);
|
2010-01-03 20:17:46 +00:00
|
|
|
XDestroyWindow(server.dsp, traywin->id);
|
2009-03-01 19:18:35 +00:00
|
|
|
XSync(server.dsp, False);
|
|
|
|
XSetErrorHandler(old);
|
2009-10-30 20:54:29 +00:00
|
|
|
g_free(traywin);
|
2009-03-01 19:18:35 +00:00
|
|
|
|
2009-02-27 22:18:30 +00:00
|
|
|
// changed in systray force resize on panel
|
|
|
|
Panel *panel = systray.area.panel;
|
|
|
|
panel->area.resize = 1;
|
|
|
|
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;
|
|
|
|
Window id;
|
|
|
|
|
|
|
|
opcode = e->data.l[1];
|
|
|
|
switch (opcode) {
|
2009-02-28 23:04:53 +00:00
|
|
|
case SYSTEM_TRAY_REQUEST_DOCK:
|
|
|
|
id = e->data.l[2];
|
2009-03-01 19:18:35 +00:00
|
|
|
if (id) add_icon(id);
|
2009-02-28 23:04:53 +00:00
|
|
|
break;
|
2009-02-25 20:04:43 +00:00
|
|
|
|
2009-02-28 23:04:53 +00:00
|
|
|
case SYSTEM_TRAY_BEGIN_MESSAGE:
|
|
|
|
case SYSTEM_TRAY_CANCEL_MESSAGE:
|
2009-06-13 19:39:41 +00:00
|
|
|
// we don't show baloons messages.
|
2009-02-28 23:04:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-06-29 18:39:44 +00:00
|
|
|
if (opcode == server.atom._NET_SYSTEM_TRAY_MESSAGE_DATA)
|
2009-06-13 19:39:41 +00:00
|
|
|
printf("message from dockapp: %s\n", e->data.b);
|
|
|
|
else
|
2009-06-29 18:39:44 +00:00
|
|
|
fprintf(stderr, "SYSTEM_TRAY : unknown message type\n");
|
2009-02-28 23:04:53 +00:00
|
|
|
break;
|
2009-02-25 20:04:43 +00:00
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-03 00:33:07 +00:00
|
|
|
void systray_render_icons(TrayWindow* traywin)
|
|
|
|
{
|
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-03 20:17:46 +00:00
|
|
|
imlib_context_set_drawable(traywin->id);
|
|
|
|
Imlib_Image image = imlib_create_image_from_drawable(0, 0, 0, traywin->width, traywin->height, 0);
|
|
|
|
imlib_context_set_image(image);
|
|
|
|
imlib_image_set_has_alpha(1);
|
|
|
|
DATA32* data = imlib_image_get_data();
|
|
|
|
if (traywin->depth == 24) {
|
2010-01-03 00:33:07 +00:00
|
|
|
createHeuristicMask(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-04 16:25:17 +00:00
|
|
|
if ( !real_transparency ) {
|
|
|
|
imlib_context_set_drawable(panel->main_win);
|
|
|
|
imlib_render_image_on_drawable(traywin->x, traywin->y);
|
|
|
|
imlib_context_set_drawable(systray.area.pix.pmap);
|
|
|
|
imlib_render_image_on_drawable(traywin->x-systray.area.posx, traywin->y-systray.area.posy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
render_image(panel->main_win, traywin->x, traywin->y, traywin->width, traywin->height);
|
|
|
|
render_image(systray.area.pix.pmap, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height);
|
|
|
|
}
|
2010-01-05 11:21:18 +00:00
|
|
|
imlib_free_image_and_decache();
|
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;
|
2009-09-27 21:33:44 +00:00
|
|
|
if (traywin->hide) continue;
|
2010-01-03 20:17:46 +00:00
|
|
|
if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0)
|
|
|
|
systray_render_icons(traywin);
|
|
|
|
else
|
|
|
|
XClearArea(server.dsp, traywin->id, 0, 0, traywin->width, traywin->height, True);
|
2009-06-13 19:39:41 +00:00
|
|
|
}
|
2010-01-03 20:17:46 +00:00
|
|
|
if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0)
|
2010-01-03 00:33:07 +00:00
|
|
|
XFlush(server.dsp);
|
2009-06-13 19:39:41 +00:00
|
|
|
}
|