2008-06-14 18:12:16 +02:00
|
|
|
/*
|
|
|
|
* systray.c - systray widget
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 <xcb/xcb.h>
|
2008-06-24 19:56:10 +02:00
|
|
|
#include <xcb/xcb_atom.h>
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
#include "widget.h"
|
2008-06-14 23:20:35 +02:00
|
|
|
#include "screen.h"
|
2008-06-14 18:12:16 +02:00
|
|
|
#include "common/xembed.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-06-24 19:56:10 +02:00
|
|
|
#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
|
|
|
|
#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
extern awesome_t globalconf;
|
|
|
|
|
|
|
|
static int
|
|
|
|
systray_draw(draw_context_t *ctx,
|
|
|
|
int screen __attribute__ ((unused)),
|
|
|
|
widget_node_t *w,
|
|
|
|
int offset, int used __attribute__ ((unused)),
|
2008-07-29 16:51:21 +02:00
|
|
|
void *p,
|
|
|
|
awesome_type_t type)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-06-14 23:20:35 +02:00
|
|
|
int i = 0, phys_screen;
|
2008-06-14 18:12:16 +02:00
|
|
|
xembed_window_t *em;
|
2008-06-24 19:56:10 +02:00
|
|
|
uint32_t orient, config_win_vals[4];
|
2008-06-14 23:20:35 +02:00
|
|
|
/* p is always a statusbar, titlebars are forbidden */
|
|
|
|
statusbar_t *sb = (statusbar_t *) p;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-06-14 23:20:35 +02:00
|
|
|
phys_screen = screen_virttophys(screen);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-06-15 10:50:50 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
|
|
|
i++;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
if(ctx->width - used > 0)
|
|
|
|
w->area.width = MIN(i * ctx->height, ctx->width - used);
|
|
|
|
else
|
|
|
|
w->area.width = 0;
|
|
|
|
w->area.height = ctx->height;
|
|
|
|
w->area.x = widget_calculate_offset(ctx->width,
|
|
|
|
w->area.width,
|
|
|
|
offset,
|
|
|
|
w->widget->align);
|
|
|
|
w->area.y = 0;
|
|
|
|
|
|
|
|
/* width */
|
|
|
|
config_win_vals[2] = w->area.height;
|
|
|
|
/* height */
|
|
|
|
config_win_vals[3] = w->area.height;
|
|
|
|
|
2008-06-14 23:20:35 +02:00
|
|
|
switch(sb->position)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
|
|
|
case Left:
|
2008-06-14 23:20:35 +02:00
|
|
|
config_win_vals[0] = sb->sw->geometry.x + w->area.y;
|
|
|
|
config_win_vals[1] = sb->sw->geometry.y + sb->sw->geometry.height
|
2008-06-14 18:12:16 +02:00
|
|
|
- w->area.x - config_win_vals[3];
|
2008-06-24 19:56:10 +02:00
|
|
|
orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
|
2008-06-14 18:12:16 +02:00
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-06-15 10:50:50 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-06-15 10:50:50 +02:00
|
|
|
if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) sb->sw->geometry.y)
|
|
|
|
{
|
|
|
|
xcb_map_window(globalconf.connection, em->win);
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH
|
2008-06-23 14:53:31 +02:00
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
2008-06-15 10:50:50 +02:00
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[1] -= config_win_vals[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_unmap_window(globalconf.connection, em->win);
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Right:
|
2008-06-24 19:56:10 +02:00
|
|
|
orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
|
2008-06-14 23:20:35 +02:00
|
|
|
config_win_vals[0] = sb->sw->geometry.x - w->area.y;
|
|
|
|
config_win_vals[1] = sb->sw->geometry.y + w->area.x;
|
2008-06-14 18:12:16 +02:00
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-06-15 10:50:50 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-06-15 10:50:50 +02:00
|
|
|
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) sb->sw->geometry.y + ctx->width)
|
|
|
|
{
|
|
|
|
xcb_map_window(globalconf.connection, em->win);
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH
|
2008-06-23 14:53:31 +02:00
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
2008-06-15 10:50:50 +02:00
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[1] += config_win_vals[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_unmap_window(globalconf.connection, em->win);
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2008-06-24 19:56:10 +02:00
|
|
|
orient = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
|
2008-06-14 18:12:16 +02:00
|
|
|
/* x */
|
2008-06-14 23:20:35 +02:00
|
|
|
config_win_vals[0] = sb->sw->geometry.x + w->area.x;
|
2008-06-14 18:12:16 +02:00
|
|
|
/* y */
|
2008-06-14 23:20:35 +02:00
|
|
|
config_win_vals[1] = sb->sw->geometry.y + w->area.y;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-06-15 10:50:50 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-06-15 10:50:50 +02:00
|
|
|
/* if(x + width < systray.x + systray.width) */
|
|
|
|
if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(w->area) + sb->sw->geometry.x)
|
|
|
|
{
|
|
|
|
xcb_map_window(globalconf.connection, em->win);
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH
|
2008-06-23 14:53:31 +02:00
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
2008-06-15 10:50:50 +02:00
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] += config_win_vals[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_unmap_window(globalconf.connection, em->win);
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-17 13:33:17 +02:00
|
|
|
/* inform that there's a widget */
|
|
|
|
globalconf.screens[phys_screen].systray.has_systray_widget = true;
|
|
|
|
|
2008-06-24 19:56:10 +02:00
|
|
|
/* set statusbar orientation */
|
|
|
|
/** \todo stop setting that property on each redraw */
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-06-30 18:55:14 +02:00
|
|
|
_NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient);
|
2008-06-24 19:56:10 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
return w->area.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_t *
|
|
|
|
systray_new(alignment_t align)
|
|
|
|
{
|
|
|
|
widget_t *w;
|
|
|
|
|
|
|
|
w = p_new(widget_t, 1);
|
|
|
|
widget_common_new(w);
|
|
|
|
w->align = align;
|
|
|
|
w->draw = systray_draw;
|
|
|
|
w->cache_flags = WIDGET_CACHE_EMBEDDED;
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|