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-10-22 17:32:17 +02:00
|
|
|
static area_t
|
|
|
|
systray_geometry(widget_t *widget, int screen, int height, int width)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-10-22 17:32:17 +02:00
|
|
|
area_t geometry;
|
2008-12-01 16:43:44 +01:00
|
|
|
int phys_screen = screen_virttophys(screen), n = 0;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
geometry.height = height;
|
2008-08-05 15:29:16 +02:00
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
if(globalconf.embedded.tab[i].phys_screen == phys_screen)
|
|
|
|
n++;
|
2008-08-05 15:29:16 +02:00
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
/** \todo use class hints */
|
2008-12-01 16:43:44 +01:00
|
|
|
geometry.width = MIN(n * height, width);
|
2008-10-22 17:32:17 +02:00
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
systray_draw(widget_t *widget, draw_context_t *ctx,
|
|
|
|
area_t geometry, int screen, wibox_t *p)
|
|
|
|
{
|
|
|
|
uint32_t orient;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-09-21 10:13:21 +02:00
|
|
|
switch(p->position)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
|
|
|
case Right:
|
2008-08-05 16:59:54 +02:00
|
|
|
case Left:
|
2008-06-24 19:56:10 +02:00
|
|
|
orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
/* set wibox orientation */
|
2008-06-24 19:56:10 +02:00
|
|
|
/** \todo stop setting that property on each redraw */
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-09-21 10:13:21 +02:00
|
|
|
globalconf.screens[p->sw.ctx.phys_screen].systray.window,
|
2008-06-30 18:55:14 +02:00
|
|
|
_NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient);
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
|
2008-11-12 14:55:30 +01:00
|
|
|
/** Initialize a systray widget.
|
|
|
|
* \param w The widget to initialize.
|
|
|
|
* \return The same widget.
|
|
|
|
*/
|
2008-06-14 18:12:16 +02:00
|
|
|
widget_t *
|
2008-11-12 14:55:30 +01:00
|
|
|
widget_systray(widget_t *w)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
|
|
|
w->draw = systray_draw;
|
2008-10-22 17:32:17 +02:00
|
|
|
w->geometry = systray_geometry;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|