2007-10-03 17:26:14 +02:00
|
|
|
/*
|
2007-10-17 10:53:32 +02:00
|
|
|
* statusbar.c - statusbar functions
|
2007-10-03 17:26:14 +02:00
|
|
|
*
|
2008-03-15 09:10:32 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-10-03 17:26:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-09-15 15:16:53 +02:00
|
|
|
*/
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
2007-09-24 17:08:47 +02:00
|
|
|
|
2008-08-05 16:59:54 +02:00
|
|
|
#include "client.h"
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "statusbar.h"
|
2007-09-15 15:26:51 +02:00
|
|
|
#include "screen.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2008-06-17 22:12:30 +02:00
|
|
|
#include "ewmh.h"
|
2007-12-15 03:42:15 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-06-18 18:31:35 +02:00
|
|
|
DO_LUA_NEW(extern, statusbar_t, statusbar, "statusbar", statusbar_ref)
|
|
|
|
DO_LUA_GC(statusbar_t, statusbar, "statusbar", statusbar_unref)
|
|
|
|
DO_LUA_EQ(statusbar_t, statusbar, "statusbar")
|
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
/** Kick out systray windows.
|
|
|
|
* \param phys_screen Physical screen number.
|
2008-05-28 08:59:01 +02:00
|
|
|
*/
|
2008-01-12 21:50:14 +01:00
|
|
|
static void
|
2008-08-05 17:23:37 +02:00
|
|
|
statusbar_systray_kickout(int phys_screen)
|
|
|
|
{
|
|
|
|
xembed_window_t *em;
|
|
|
|
uint32_t config_win_vals_off[2] = { -512, -512 };
|
|
|
|
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
|
|
|
if(em->phys_screen == phys_screen)
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y,
|
|
|
|
config_win_vals_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
statusbar_systray_refresh(statusbar_t *statusbar)
|
2007-12-15 03:42:15 +01:00
|
|
|
{
|
2008-08-05 16:59:54 +02:00
|
|
|
widget_node_t *systray;
|
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
if(statusbar->screen == SCREEN_UNDEF)
|
|
|
|
return;
|
2008-05-30 13:08:11 +02:00
|
|
|
|
2008-08-05 16:59:54 +02:00
|
|
|
for(systray = statusbar->widgets; systray; systray = systray->next)
|
|
|
|
if(systray->widget->type == systray_new)
|
|
|
|
{
|
2008-08-05 17:23:37 +02:00
|
|
|
uint32_t config_win_vals[4];
|
|
|
|
uint32_t config_win_vals_off[2] = { -512, -512 };
|
|
|
|
xembed_window_t *em;
|
|
|
|
position_t pos;
|
2007-12-30 12:33:57 +01:00
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
if(statusbar->position
|
|
|
|
&& systray->widget->isvisible)
|
|
|
|
{
|
|
|
|
pos = statusbar->position;
|
|
|
|
/* width */
|
|
|
|
config_win_vals[2] = systray->area.height;
|
|
|
|
/* height */
|
|
|
|
config_win_vals[3] = systray->area.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* hide */
|
|
|
|
pos = Off;
|
|
|
|
|
|
|
|
switch(pos)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
config_win_vals[0] = statusbar->sw->geometry.x + systray->area.y;
|
|
|
|
config_win_vals[1] = statusbar->sw->geometry.y + statusbar->sw->geometry.height
|
|
|
|
- systray->area.x - config_win_vals[3];
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
|
|
|
if(em->phys_screen == statusbar->phys_screen)
|
2008-08-05 16:59:54 +02:00
|
|
|
{
|
2008-08-10 20:58:03 +02:00
|
|
|
if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) statusbar->sw->geometry.y)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[1] -= config_win_vals[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y,
|
|
|
|
config_win_vals_off);
|
2008-08-05 16:59:54 +02:00
|
|
|
}
|
2008-08-05 17:23:37 +02:00
|
|
|
client_stack();
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
config_win_vals[0] = statusbar->sw->geometry.x - systray->area.y;
|
|
|
|
config_win_vals[1] = statusbar->sw->geometry.y + systray->area.x;
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
|
|
|
if(em->phys_screen == statusbar->phys_screen)
|
2008-08-05 16:59:54 +02:00
|
|
|
{
|
2008-08-10 20:58:03 +02:00
|
|
|
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw->geometry.y + statusbar->ctx->width)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[1] += config_win_vals[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y,
|
|
|
|
config_win_vals_off);
|
2008-08-05 16:59:54 +02:00
|
|
|
}
|
2008-08-05 17:23:37 +02:00
|
|
|
client_stack();
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
config_win_vals[0] = statusbar->sw->geometry.x + systray->area.x;
|
|
|
|
config_win_vals[1] = statusbar->sw->geometry.y + systray->area.y;
|
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
|
|
|
if(em->phys_screen == statusbar->phys_screen)
|
2008-08-05 16:59:54 +02:00
|
|
|
{
|
2008-08-05 17:23:37 +02:00
|
|
|
/* if(x + width < systray.x + systray.width) */
|
2008-08-10 20:58:03 +02:00
|
|
|
if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(systray->area) + statusbar->sw->geometry.x)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] += config_win_vals[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y,
|
|
|
|
config_win_vals_off);
|
2008-08-05 16:59:54 +02:00
|
|
|
}
|
2008-08-05 17:23:37 +02:00
|
|
|
client_stack();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusbar_systray_kickout(statusbar->phys_screen);
|
|
|
|
break;
|
|
|
|
}
|
2008-08-05 16:59:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-08-05 17:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Draw a statusbar.
|
|
|
|
* \param statusbar The statusbar to draw.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
statusbar_draw(statusbar_t *statusbar)
|
|
|
|
{
|
|
|
|
statusbar->need_update = false;
|
|
|
|
|
|
|
|
if(statusbar->position)
|
|
|
|
{
|
|
|
|
widget_render(statusbar->widgets, statusbar->ctx, statusbar->sw->gc,
|
|
|
|
statusbar->sw->pixmap,
|
|
|
|
statusbar->screen, statusbar->position,
|
|
|
|
statusbar->sw->geometry.x, statusbar->sw->geometry.y,
|
|
|
|
statusbar, AWESOME_TYPE_STATUSBAR);
|
|
|
|
simplewindow_refresh_pixmap(statusbar->sw);
|
2008-08-05 16:59:54 +02:00
|
|
|
}
|
2008-08-08 15:47:09 +02:00
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
statusbar_systray_refresh(statusbar);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
2008-05-31 16:04:46 +02:00
|
|
|
/** Statusbar refresh function.
|
2008-05-28 08:59:01 +02:00
|
|
|
*/
|
2008-05-31 16:04:46 +02:00
|
|
|
void
|
|
|
|
statusbar_refresh(void)
|
2008-05-27 11:17:51 +02:00
|
|
|
{
|
2008-05-31 16:04:46 +02:00
|
|
|
int screen;
|
|
|
|
statusbar_t *statusbar;
|
2008-05-27 11:17:51 +02:00
|
|
|
|
2008-05-31 16:04:46 +02:00
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
|
|
|
if(statusbar->need_update)
|
|
|
|
statusbar_draw(statusbar);
|
2008-05-27 11:17:51 +02:00
|
|
|
}
|
|
|
|
|
2008-05-28 08:59:01 +02:00
|
|
|
/** Update the statusbar position. It deletes every statusbar resources and
|
|
|
|
* create them back.
|
|
|
|
* \param statusbar The statusbar.
|
|
|
|
*/
|
2008-08-14 18:24:31 +02:00
|
|
|
void
|
2008-07-24 17:37:24 +02:00
|
|
|
statusbar_position_update(statusbar_t *statusbar)
|
2008-01-16 17:47:12 +01:00
|
|
|
{
|
2008-04-11 11:27:36 +02:00
|
|
|
statusbar_t *sb;
|
2008-05-20 15:39:47 +02:00
|
|
|
area_t area;
|
2008-06-04 16:13:41 +02:00
|
|
|
xcb_pixmap_t dw;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_screen_t *s = NULL;
|
2008-05-20 15:39:47 +02:00
|
|
|
bool ignore = false;
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
globalconf.screens[statusbar->screen].need_arrange = true;
|
2008-05-27 15:23:24 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_delete(&statusbar->sw);
|
|
|
|
draw_context_delete(&statusbar->ctx);
|
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
if(statusbar->position == Off)
|
2008-05-20 15:39:47 +02:00
|
|
|
return;
|
2008-01-16 17:47:12 +01:00
|
|
|
|
2008-08-11 17:14:02 +02:00
|
|
|
area = screen_area_get(&globalconf.screens[statusbar->screen].geometry,
|
2008-05-20 15:39:47 +02:00
|
|
|
NULL,
|
|
|
|
&globalconf.screens[statusbar->screen].padding);
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-04-11 11:27:36 +02:00
|
|
|
/* Top and Bottom statusbar_t have prio */
|
2008-01-16 17:47:12 +01:00
|
|
|
for(sb = globalconf.screens[statusbar->screen].statusbar; sb; sb = sb->next)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
/* Ignore every statusbar after me that is in the same position */
|
|
|
|
if(statusbar == sb)
|
|
|
|
{
|
|
|
|
ignore = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if(ignore && statusbar->position == sb->position)
|
|
|
|
continue;
|
2008-01-16 17:47:12 +01:00
|
|
|
switch(sb->position)
|
|
|
|
{
|
|
|
|
case Left:
|
2008-05-20 15:39:47 +02:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
area.x += statusbar->height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-16 17:47:12 +01:00
|
|
|
case Right:
|
2008-05-20 15:39:47 +02:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Right:
|
|
|
|
area.x -= statusbar->height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 17:47:12 +01:00
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
case Top:
|
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
area.y += sb->height;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
area.height -= sb->height;
|
|
|
|
area.y += sb->height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 17:47:12 +01:00
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
case Bottom:
|
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Bottom:
|
|
|
|
area.y -= sb->height;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
area.height -= sb->height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-24 10:37:16 +01:00
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
default:
|
2008-01-24 10:37:16 +01:00
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-01-24 10:37:16 +01:00
|
|
|
}
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2008-03-20 09:08:15 +01:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Right:
|
|
|
|
case Left:
|
2008-06-03 11:47:05 +02:00
|
|
|
if(!statusbar->width_user)
|
2008-05-24 09:06:04 +02:00
|
|
|
statusbar->width = area.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
statusbar->sw =
|
|
|
|
simplewindow_new(globalconf.connection, statusbar->phys_screen, 0, 0,
|
|
|
|
statusbar->height, statusbar->width, 0);
|
2008-06-17 16:55:24 +02:00
|
|
|
s = xutil_screen_get(globalconf.connection, statusbar->phys_screen);
|
2008-03-20 09:08:15 +01:00
|
|
|
/* we need a new pixmap this way [ ] to render */
|
2008-03-21 16:50:17 +01:00
|
|
|
dw = xcb_generate_id(globalconf.connection);
|
|
|
|
xcb_create_pixmap(globalconf.connection,
|
2008-03-27 16:05:37 +01:00
|
|
|
s->root_depth, dw, s->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
statusbar->width, statusbar->height);
|
|
|
|
statusbar->ctx = draw_context_new(globalconf.connection,
|
2008-05-20 15:39:47 +02:00
|
|
|
statusbar->phys_screen,
|
2008-03-20 09:08:15 +01:00
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
2008-06-02 12:18:17 +02:00
|
|
|
dw,
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
&statusbar->colors.fg,
|
|
|
|
&statusbar->colors.bg);
|
2008-03-20 09:08:15 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-06-03 11:47:05 +02:00
|
|
|
if(!statusbar->width_user)
|
2008-05-24 09:06:04 +02:00
|
|
|
statusbar->width = area.width;
|
2008-05-20 15:39:47 +02:00
|
|
|
statusbar->sw =
|
|
|
|
simplewindow_new(globalconf.connection, statusbar->phys_screen, 0, 0,
|
|
|
|
statusbar->width, statusbar->height, 0);
|
2008-03-21 16:50:17 +01:00
|
|
|
statusbar->ctx = draw_context_new(globalconf.connection,
|
2008-05-20 15:39:47 +02:00
|
|
|
statusbar->phys_screen,
|
2008-03-20 09:08:15 +01:00
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
2008-06-04 16:13:41 +02:00
|
|
|
statusbar->sw->pixmap,
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
&statusbar->colors.fg,
|
|
|
|
&statusbar->colors.bg);
|
2008-03-20 09:08:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
2008-05-24 11:08:34 +02:00
|
|
|
default:
|
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
simplewindow_move(statusbar->sw, area.x, area.y);
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
simplewindow_move(statusbar->sw,
|
|
|
|
area.x + area.width - statusbar->width, area.y);
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
simplewindow_move(statusbar->sw,
|
|
|
|
area.x + (area.width - statusbar->width) / 2, area.y);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
simplewindow_move(statusbar->sw,
|
|
|
|
area.x, (area.y + area.height) - statusbar->height);
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
simplewindow_move(statusbar->sw,
|
|
|
|
area.x + area.width - statusbar->width,
|
|
|
|
(area.y + area.height) - statusbar->height);
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
simplewindow_move(statusbar->sw,
|
|
|
|
area.x + (area.width - statusbar->width) / 2,
|
|
|
|
(area.y + area.height) - statusbar->height);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
simplewindow_move(statusbar->sw, area.x,
|
|
|
|
(area.y + area.height) - statusbar->sw->geometry.height);
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
simplewindow_move(statusbar->sw, area.x, area.y);
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
simplewindow_move(statusbar->sw, area.x, (area.y + area.height - statusbar->width) / 2);
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Right:
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height, area.y);
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height,
|
|
|
|
area.y + area.height - statusbar->width);
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height,
|
|
|
|
(area.y + area.height - statusbar->width) / 2);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_map_window(globalconf.connection, statusbar->sw->window);
|
2008-05-30 10:24:13 +02:00
|
|
|
|
2008-05-31 16:04:46 +02:00
|
|
|
/* Set need update */
|
|
|
|
statusbar->need_update = true;
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2008-05-28 08:59:01 +02:00
|
|
|
/** Convert a statusbar to a printable string.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A statusbar.
|
2008-05-28 08:59:01 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_statusbar_tostring(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
statusbar_t **p = luaA_checkudata(L, 1, "statusbar");
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_pushfstring(L, "[statusbar udata(%p) name(%s)]", *p, (*p)->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 08:59:01 +02:00
|
|
|
/** Create a new statusbar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-18 20:00:24 +02:00
|
|
|
* \lparam A table with at least a name attribute. Optionaly defined values are:
|
2008-05-28 08:59:01 +02:00
|
|
|
* position, align, fg, bg, width and height.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A brand new statusbar.
|
2008-05-28 08:59:01 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_statusbar_new(lua_State *L)
|
|
|
|
{
|
2008-06-08 18:05:32 +02:00
|
|
|
statusbar_t *sb;
|
2008-06-23 14:01:33 +02:00
|
|
|
const char *buf;
|
|
|
|
size_t len;
|
2008-08-12 14:53:57 +02:00
|
|
|
xcolor_init_request_t reqs[2];
|
|
|
|
int8_t i, reqs_nbr = -1;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
luaA_checktable(L, 2);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
if(!(buf = luaA_getopt_string(L, 2, "name", NULL)))
|
2008-06-30 13:50:49 +02:00
|
|
|
luaL_error(L, "object statusbar must have a name");
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 13:50:49 +02:00
|
|
|
sb = p_new(statusbar_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 13:50:49 +02:00
|
|
|
sb->name = a_strdup(buf);
|
2008-07-01 16:31:22 +02:00
|
|
|
|
2008-07-24 18:20:46 +02:00
|
|
|
sb->colors.fg = globalconf.colors.fg;
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&sb->colors.fg,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-03-19 16:32:37 +01:00
|
|
|
|
2008-07-24 18:20:46 +02:00
|
|
|
sb->colors.bg = globalconf.colors.bg;
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&sb->colors.bg,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
|
2008-06-24 22:24:13 +02:00
|
|
|
sb->align = draw_align_fromstr(buf, len);
|
2008-05-24 11:08:34 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
sb->width = luaA_getopt_number(L, 2, "width", 0);
|
2008-06-08 18:05:32 +02:00
|
|
|
if(sb->width > 0)
|
|
|
|
sb->width_user = true;
|
2008-06-30 14:01:55 +02:00
|
|
|
sb->height = luaA_getopt_number(L, 2, "height", 0);
|
2008-06-08 18:05:32 +02:00
|
|
|
if(sb->height <= 0)
|
2008-05-20 15:39:47 +02:00
|
|
|
/* 1.5 as default factor, it fits nice but no one knows why */
|
2008-06-08 18:05:32 +02:00
|
|
|
sb->height = 1.5 * globalconf.font->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "position", "top", &len);
|
2008-06-23 14:01:33 +02:00
|
|
|
sb->position = position_fromstr(buf, len);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
sb->screen = SCREEN_UNDEF;
|
|
|
|
|
2008-08-12 14:53:57 +02:00
|
|
|
for(i = 0; i <= reqs_nbr; i++)
|
|
|
|
xcolor_init_reply(globalconf.connection, reqs[i]);
|
|
|
|
|
2008-06-18 18:31:35 +02:00
|
|
|
return luaA_statusbar_userdata_new(L, sb);
|
2008-06-04 19:21:21 +02:00
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Statusbar object.
|
2008-07-01 16:31:22 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \luastack
|
2008-07-24 17:37:24 +02:00
|
|
|
* \lfield screen Screen number.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \lfield align The alignment.
|
|
|
|
* \lfield fg Foreground color.
|
|
|
|
* \lfield bg Background color.
|
|
|
|
* \lfield position The position.
|
2008-08-08 15:47:09 +02:00
|
|
|
* \lfield widget The statusbar widgets.
|
2008-07-01 16:31:22 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_statusbar_index(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
2008-08-08 15:47:09 +02:00
|
|
|
int i = 0;
|
|
|
|
widget_node_t *witer;
|
2008-07-01 16:31:22 +02:00
|
|
|
statusbar_t **statusbar = luaA_checkudata(L, 1, "statusbar");
|
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
|
|
|
|
2008-07-01 19:25:58 +02:00
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
2008-07-01 16:31:22 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-07-24 17:37:24 +02:00
|
|
|
case A_TK_SCREEN:
|
|
|
|
if((*statusbar)->screen == SCREEN_UNDEF)
|
|
|
|
return 0;
|
|
|
|
lua_pushnumber(L, (*statusbar)->screen + 1);
|
|
|
|
break;
|
2008-07-01 16:31:22 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
lua_pushstring(L, draw_align_tostr((*statusbar)->align));
|
|
|
|
break;
|
2008-07-01 16:50:03 +02:00
|
|
|
case A_TK_FG:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*statusbar)->colors.fg);
|
2008-07-01 16:50:03 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BG:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*statusbar)->colors.bg);
|
2008-07-01 16:50:03 +02:00
|
|
|
break;
|
2008-07-01 17:00:06 +02:00
|
|
|
case A_TK_POSITION:
|
|
|
|
lua_pushstring(L, position_tostr((*statusbar)->position));
|
|
|
|
break;
|
2008-08-08 15:47:09 +02:00
|
|
|
case A_TK_WIDGETS:
|
|
|
|
lua_newtable(L);
|
|
|
|
for(witer = (*statusbar)->widgets; witer; witer = witer->next)
|
|
|
|
{
|
|
|
|
luaA_widget_userdata_new(L, witer->widget);
|
|
|
|
lua_rawseti(L, -2, ++i);
|
|
|
|
}
|
|
|
|
break;
|
2008-07-01 16:31:22 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
/** Remove a statubar from a screen.
|
|
|
|
* \param statusbar Statusbar to detach from screen.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
statusbar_remove(statusbar_t *statusbar)
|
|
|
|
{
|
|
|
|
if(statusbar->screen != SCREEN_UNDEF)
|
|
|
|
{
|
|
|
|
position_t p;
|
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
statusbar_systray_kickout(statusbar->phys_screen);
|
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
/* save position */
|
|
|
|
p = statusbar->position;
|
|
|
|
statusbar->position = Off;
|
|
|
|
statusbar_position_update(statusbar);
|
|
|
|
/* restore position */
|
|
|
|
statusbar->position = p;
|
|
|
|
|
|
|
|
statusbar_list_detach(&globalconf.screens[statusbar->screen].statusbar, statusbar);
|
|
|
|
globalconf.screens[statusbar->screen].need_arrange = true;
|
|
|
|
statusbar->screen = SCREEN_UNDEF;
|
|
|
|
statusbar_unref(&statusbar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 16:31:22 +02:00
|
|
|
/** Statusbar newindex.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_statusbar_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
2008-07-01 17:00:06 +02:00
|
|
|
statusbar_t *s, **statusbar = luaA_checkudata(L, 1, "statusbar");
|
2008-07-01 16:31:22 +02:00
|
|
|
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
2008-07-01 17:00:06 +02:00
|
|
|
position_t p;
|
2008-07-24 17:37:24 +02:00
|
|
|
int screen;
|
2008-08-08 15:47:09 +02:00
|
|
|
widget_node_t *witer;
|
2008-07-01 16:31:22 +02:00
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-07-24 17:37:24 +02:00
|
|
|
case A_TK_SCREEN:
|
|
|
|
if(lua_isnil(L, 3))
|
|
|
|
statusbar_remove(*statusbar);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screen = luaL_checknumber(L, 3) - 1;
|
2008-08-08 15:47:09 +02:00
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
luaA_checkscreen(screen);
|
|
|
|
|
|
|
|
if((*statusbar)->screen == screen)
|
|
|
|
luaL_error(L, "this statusbar is already on screen %d",
|
|
|
|
(*statusbar)->screen + 1);
|
|
|
|
|
|
|
|
/* Check for uniq name and id. */
|
|
|
|
for(s = globalconf.screens[screen].statusbar; s; s = s->next)
|
|
|
|
if(!a_strcmp(s->name, (*statusbar)->name))
|
|
|
|
luaL_error(L, "a statusbar with that name is already on screen %d\n",
|
|
|
|
screen + 1);
|
|
|
|
|
|
|
|
statusbar_remove(*statusbar);
|
|
|
|
|
|
|
|
(*statusbar)->screen = screen;
|
|
|
|
(*statusbar)->phys_screen = screen_virttophys(screen);
|
|
|
|
|
|
|
|
statusbar_list_append(&globalconf.screens[screen].statusbar, *statusbar);
|
|
|
|
statusbar_ref(statusbar);
|
|
|
|
|
|
|
|
/* All the other statusbar and ourselves need to be repositioned */
|
|
|
|
for(s = globalconf.screens[screen].statusbar; s; s = s->next)
|
|
|
|
statusbar_position_update(s);
|
|
|
|
|
|
|
|
ewmh_update_workarea((*statusbar)->phys_screen);
|
|
|
|
}
|
|
|
|
break;
|
2008-07-01 16:31:22 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
buf = luaL_checklstring(L, 3, &len);
|
|
|
|
(*statusbar)->align = draw_align_fromstr(buf, len);
|
2008-07-24 17:37:24 +02:00
|
|
|
statusbar_position_update(*statusbar);
|
2008-07-01 16:31:22 +02:00
|
|
|
break;
|
2008-07-01 16:50:03 +02:00
|
|
|
case A_TK_FG:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
if(xcolor_init_reply(globalconf.connection,
|
|
|
|
xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&(*statusbar)->colors.fg,
|
|
|
|
globalconf.default_screen,
|
|
|
|
buf, len)))
|
2008-07-10 15:30:16 +02:00
|
|
|
{
|
|
|
|
if((*statusbar)->ctx)
|
|
|
|
(*statusbar)->ctx->fg = (*statusbar)->colors.fg;
|
|
|
|
(*statusbar)->need_update = true;
|
|
|
|
}
|
2008-07-01 16:50:03 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BG:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
2008-08-12 14:53:57 +02:00
|
|
|
if(xcolor_init_reply(globalconf.connection,
|
|
|
|
xcolor_init_unchecked(globalconf.connection,
|
|
|
|
&(*statusbar)->colors.bg,
|
|
|
|
globalconf.default_screen, buf, len)))
|
2008-07-10 15:30:16 +02:00
|
|
|
{
|
|
|
|
if((*statusbar)->ctx)
|
|
|
|
(*statusbar)->ctx->bg = (*statusbar)->colors.bg;
|
2008-07-01 16:50:03 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
(*statusbar)->need_update = true;
|
|
|
|
}
|
2008-07-01 16:50:03 +02:00
|
|
|
break;
|
2008-07-01 17:00:06 +02:00
|
|
|
case A_TK_POSITION:
|
|
|
|
buf = luaL_checklstring(L, 3, &len);
|
|
|
|
p = position_fromstr(buf, len);
|
|
|
|
if(p != (*statusbar)->position)
|
|
|
|
{
|
|
|
|
(*statusbar)->position = p;
|
2008-08-12 08:22:37 +02:00
|
|
|
if((*statusbar)->screen != SCREEN_UNDEF)
|
|
|
|
{
|
|
|
|
for(s = globalconf.screens[(*statusbar)->screen].statusbar; s; s = s->next)
|
|
|
|
statusbar_position_update(s);
|
|
|
|
ewmh_update_workarea((*statusbar)->phys_screen);
|
|
|
|
}
|
2008-07-01 17:00:06 +02:00
|
|
|
}
|
2008-08-08 15:47:09 +02:00
|
|
|
break;
|
|
|
|
case A_TK_WIDGETS:
|
|
|
|
luaA_checktable(L, 3);
|
|
|
|
|
|
|
|
/* remove all widgets */
|
|
|
|
for(witer = (*statusbar)->widgets; witer; witer = (*statusbar)->widgets)
|
|
|
|
{
|
|
|
|
if(witer->widget->detach)
|
|
|
|
witer->widget->detach(witer->widget, *statusbar);
|
|
|
|
widget_unref(&witer->widget);
|
|
|
|
widget_node_list_detach(&(*statusbar)->widgets, witer);
|
|
|
|
p_delete(&witer);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*statusbar)->need_update = true;
|
|
|
|
|
|
|
|
/* now read all widgets and add them */
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 3))
|
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, -1, "widget");
|
|
|
|
widget_node_t *w = p_new(widget_node_t, 1);
|
|
|
|
w->widget = *widget;
|
|
|
|
widget_node_list_append(&(*statusbar)->widgets, w);
|
|
|
|
widget_ref(widget);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2008-07-01 17:00:06 +02:00
|
|
|
break;
|
2008-07-01 16:31:22 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
const struct luaL_reg awesome_statusbar_methods[] =
|
|
|
|
{
|
2008-06-30 14:01:55 +02:00
|
|
|
{ "__call", luaA_statusbar_new },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_statusbar_meta[] =
|
|
|
|
{
|
2008-07-01 16:31:22 +02:00
|
|
|
{ "__index", luaA_statusbar_index },
|
|
|
|
{ "__newindex", luaA_statusbar_newindex },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "__gc", luaA_statusbar_gc },
|
|
|
|
{ "__eq", luaA_statusbar_eq },
|
|
|
|
{ "__tostring", luaA_statusbar_tostring },
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|