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
|
2009-04-17 16:14:09 +02:00
|
|
|
systray_geometry(widget_t *widget, screen_t *screen, int height, int width)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-10-22 17:32:17 +02:00
|
|
|
area_t geometry;
|
2009-04-18 17:51:31 +02:00
|
|
|
int phys_screen = screen_virttophys(screen_array_indexof(&globalconf.screens, 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
|
|
|
|
2009-05-24 12:17:15 +02:00
|
|
|
geometry.x = geometry.y = 0;
|
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2009-05-05 19:55:29 +02:00
|
|
|
static area_t
|
|
|
|
systray_extents(lua_State *L, widget_t *widget)
|
|
|
|
{
|
|
|
|
area_t geometry;
|
|
|
|
int screen = screen_virttophys(luaL_optnumber(L, -1, 1)), n = 0;
|
|
|
|
|
|
|
|
geometry.height = 0;
|
|
|
|
int width = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
if(globalconf.embedded.tab[i].phys_screen == screen)
|
|
|
|
{
|
|
|
|
xcb_get_geometry_cookie_t geo = xcb_get_geometry(globalconf.connection, globalconf.embedded.tab[i].win);
|
|
|
|
xcb_get_geometry_reply_t *g = xcb_get_geometry_reply(globalconf.connection, geo, NULL);
|
|
|
|
|
|
|
|
n++;
|
|
|
|
if(g->height > geometry.height)
|
|
|
|
geometry.height = g->height;
|
|
|
|
if(g->width > width)
|
|
|
|
width = g->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
geometry.width = width * n;
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-04-17 16:14:09 +02:00
|
|
|
globalconf.screens.tab[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;
|
2009-05-05 19:55:29 +02:00
|
|
|
w->extents = systray_extents;
|
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
|