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"
|
2009-05-10 14:55:13 +02:00
|
|
|
#include "wibox.h"
|
2009-02-10 17:30:57 +01:00
|
|
|
#include "structs.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
|
|
|
|
|
2009-05-29 01:31:57 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* systray height */
|
|
|
|
int height;
|
|
|
|
} systray_data_t;
|
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
static area_t
|
2009-02-10 17:30:57 +01:00
|
|
|
systray_geometry(widget_t *widget, int screen)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-10-22 17:32:17 +02:00
|
|
|
area_t geometry;
|
2009-05-29 01:31:57 +02:00
|
|
|
int phys_screen = screen_virttophys(screen), n = 0;
|
|
|
|
systray_data_t *d = widget->data;
|
2009-05-05 19:55:29 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
2009-02-10 17:30:57 +01:00
|
|
|
if(globalconf.embedded.tab[i].phys_screen == phys_screen)
|
2009-05-05 19:55:29 +02:00
|
|
|
n++;
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
/** \todo use class hints */
|
2009-05-29 01:31:57 +02:00
|
|
|
geometry.width = d->height * n;
|
|
|
|
geometry.height = d->height;
|
|
|
|
geometry.x = geometry.y = 0;
|
2009-02-10 17:30:57 +01:00
|
|
|
|
2009-05-05 19:55:29 +02:00
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
static area_t
|
|
|
|
systray_extents(lua_State *L, widget_t *widget)
|
|
|
|
{
|
|
|
|
int screen = screen_virttophys(luaL_optnumber(L, -1, 1));
|
|
|
|
|
|
|
|
return systray_geometry(widget, screen);
|
|
|
|
}
|
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
static void
|
|
|
|
systray_draw(widget_t *widget, draw_context_t *ctx,
|
2009-04-17 16:14:09 +02:00
|
|
|
area_t geometry, wibox_t *p)
|
2008-10-22 17:32:17 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:31:57 +02:00
|
|
|
systray_data_t *d = widget->data;
|
2009-07-28 16:04:58 +02:00
|
|
|
d->height = p->geometry.height;
|
2009-05-29 01:31:57 +02:00
|
|
|
|
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,
|
2009-07-28 16:04:58 +02:00
|
|
|
globalconf.screens.tab[p->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;
|
2009-05-05 19:55:29 +02:00
|
|
|
w->extents = systray_extents;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2009-05-29 01:31:57 +02:00
|
|
|
systray_data_t *d = w->data = p_new(systray_data_t, 1);
|
|
|
|
d->height = 0;
|
|
|
|
|
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
|