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-09-21 10:13:21 +02:00
|
|
|
#include "wibox.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-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)
|
|
|
|
{
|
2008-09-01 17:54:53 +02:00
|
|
|
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
|
|
|
|
|
2008-09-20 21:24:16 +02:00
|
|
|
/* Who! Check that we're not deleting a statusbar with a systray, because it
|
|
|
|
* may be its parent. If so, we reparent to root before, otherwise it will
|
|
|
|
* hurt very much. */
|
2008-09-01 17:54:53 +02:00
|
|
|
xcb_reparent_window(globalconf.connection,
|
|
|
|
globalconf.screens[phys_screen].systray.window,
|
|
|
|
s->root, -512, -512);
|
|
|
|
|
|
|
|
globalconf.screens[phys_screen].systray.parent = s->root;
|
2008-08-05 17:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-09-21 10:13:21 +02:00
|
|
|
statusbar_systray_refresh(wibox_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-09-01 17:54:53 +02:00
|
|
|
uint32_t config_back[] = { statusbar->colors.bg.pixel };
|
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;
|
2008-09-20 21:24:16 +02:00
|
|
|
int phys_screen = statusbar->sw.ctx.phys_screen;
|
2007-12-30 12:33:57 +01:00
|
|
|
|
2008-09-23 17:20:07 +02:00
|
|
|
if(statusbar->isvisible
|
2008-09-01 17:54:53 +02:00
|
|
|
&& systray->widget->isvisible
|
|
|
|
&& systray->area.width)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
|
|
|
pos = statusbar->position;
|
2008-09-01 17:54:53 +02:00
|
|
|
|
|
|
|
/* Set background of the systray window. */
|
|
|
|
xcb_change_window_attributes(globalconf.connection,
|
2008-09-20 16:19:10 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-09-01 17:54:53 +02:00
|
|
|
XCB_CW_BACK_PIXEL, config_back);
|
|
|
|
/* Map it. */
|
2008-09-20 16:19:10 +02:00
|
|
|
xcb_map_window(globalconf.connection, globalconf.screens[phys_screen].systray.window);
|
2008-09-01 17:54:53 +02:00
|
|
|
/* Move it. */
|
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
config_win_vals[0] = systray->area.y;
|
2008-09-20 21:24:16 +02:00
|
|
|
config_win_vals[1] = statusbar->sw.geometry.height - systray->area.x - systray->area.width;
|
2008-09-01 17:54:53 +02:00
|
|
|
config_win_vals[2] = systray->area.height;
|
|
|
|
config_win_vals[3] = systray->area.width;
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
config_win_vals[0] = systray->area.y;
|
|
|
|
config_win_vals[1] = systray->area.x;
|
|
|
|
config_win_vals[2] = systray->area.height;
|
|
|
|
config_win_vals[3] = systray->area.width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
config_win_vals[0] = systray->area.x;
|
|
|
|
config_win_vals[1] = systray->area.y;
|
|
|
|
config_win_vals[2] = systray->area.width;
|
|
|
|
config_win_vals[3] = systray->area.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* reparent */
|
2008-09-20 21:24:16 +02:00
|
|
|
if(globalconf.screens[phys_screen].systray.parent != statusbar->sw.window)
|
2008-09-01 17:54:53 +02:00
|
|
|
{
|
|
|
|
xcb_reparent_window(globalconf.connection,
|
2008-09-20 16:19:10 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-09-20 21:24:16 +02:00
|
|
|
statusbar->sw.window,
|
2008-09-01 17:54:53 +02:00
|
|
|
config_win_vals[0], config_win_vals[1]);
|
2008-09-20 21:24:16 +02:00
|
|
|
globalconf.screens[phys_screen].systray.parent = statusbar->sw.window;
|
2008-09-01 17:54:53 +02:00
|
|
|
}
|
|
|
|
xcb_configure_window(globalconf.connection,
|
2008-09-20 16:19:10 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-09-01 17:54:53 +02:00
|
|
|
XCB_CONFIG_WINDOW_X
|
|
|
|
| XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH
|
|
|
|
| XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_win_vals);
|
|
|
|
/* width = height = systray height */
|
|
|
|
config_win_vals[2] = config_win_vals[3] = systray->area.height;
|
|
|
|
config_win_vals[0] = 0;
|
2008-08-05 17:23:37 +02:00
|
|
|
}
|
|
|
|
else
|
2008-09-01 17:54:53 +02:00
|
|
|
{
|
2008-09-20 16:19:10 +02:00
|
|
|
xcb_unmap_window(globalconf.connection, globalconf.screens[phys_screen].systray.window);
|
2008-09-23 17:20:07 +02:00
|
|
|
statusbar_systray_kickout(phys_screen);
|
|
|
|
break;
|
2008-09-01 17:54:53 +02:00
|
|
|
}
|
2008-08-25 23:19:49 +02:00
|
|
|
|
2008-08-05 17:23:37 +02:00
|
|
|
switch(pos)
|
|
|
|
{
|
|
|
|
case Left:
|
2008-09-01 17:54:53 +02:00
|
|
|
config_win_vals[1] = systray->area.width - config_win_vals[3];
|
2008-08-05 17:23:37 +02:00
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-09-20 16:19:10 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
2008-08-05 16:59:54 +02:00
|
|
|
{
|
2008-09-20 21:24:16 +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
|
|
|
break;
|
|
|
|
case Right:
|
2008-09-01 17:54:53 +02:00
|
|
|
config_win_vals[1] = 0;
|
2008-08-05 17:23:37 +02:00
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-09-20 16:19:10 +02:00
|
|
|
if(em->phys_screen == phys_screen)
|
2008-08-05 16:59:54 +02:00
|
|
|
{
|
2008-09-20 21:24:16 +02:00
|
|
|
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw.geometry.y + statusbar->sw.geometry.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
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2008-09-01 17:54:53 +02:00
|
|
|
config_win_vals[1] = 0;
|
2008-08-05 17:23:37 +02:00
|
|
|
for(em = globalconf.embedded; em; em = em->next)
|
2008-09-20 16:19:10 +02:00
|
|
|
if(em->phys_screen == 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-09-20 21:24:16 +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
|
|
|
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
|
2008-09-21 10:13:21 +02:00
|
|
|
statusbar_draw(wibox_t *statusbar)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
|
|
|
statusbar->need_update = false;
|
|
|
|
|
2008-09-23 17:20:07 +02:00
|
|
|
if(statusbar->isvisible)
|
2008-08-05 17:23:37 +02:00
|
|
|
{
|
2008-09-20 21:24:16 +02:00
|
|
|
widget_render(statusbar->widgets, &statusbar->sw.ctx, statusbar->sw.gc,
|
|
|
|
statusbar->sw.pixmap,
|
2008-08-05 17:23:37 +02:00
|
|
|
statusbar->screen, statusbar->position,
|
2008-09-20 21:24:16 +02:00
|
|
|
statusbar->sw.geometry.x, statusbar->sw.geometry.y,
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar);
|
2008-09-20 21:24:16 +02:00
|
|
|
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-08-25 13:32:26 +02:00
|
|
|
/** Get a statusbar by its window.
|
|
|
|
* \param w The window id.
|
|
|
|
* \return A statusbar if found, NULL otherwise.
|
|
|
|
*/
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_t *
|
2008-08-25 13:32:26 +02:00
|
|
|
statusbar_getbywin(xcb_window_t w)
|
|
|
|
{
|
2008-09-20 16:45:43 +02:00
|
|
|
for(int screen = 0; screen < globalconf.nscreen; screen++)
|
|
|
|
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
|
|
|
|
{
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_t *s = globalconf.screens[screen].statusbars.tab[i];
|
2008-09-20 21:24:16 +02:00
|
|
|
if(s->sw.window == w)
|
2008-08-25 13:32:26 +02:00
|
|
|
return s;
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-08-25 13:32:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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-09-20 16:45:43 +02:00
|
|
|
for(int screen = 0; screen < globalconf.nscreen; screen++)
|
|
|
|
for(int i = 0; i < globalconf.screens[screen].statusbars.len; i++)
|
|
|
|
{
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_t *s = globalconf.screens[screen].statusbars.tab[i];
|
2008-09-20 16:45:43 +02:00
|
|
|
if(s->need_update)
|
|
|
|
statusbar_draw(s);
|
|
|
|
}
|
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-09-21 10:13:21 +02:00
|
|
|
statusbar_position_update(wibox_t *statusbar)
|
2008-01-16 17:47:12 +01:00
|
|
|
{
|
2008-09-22 19:11:39 +02:00
|
|
|
area_t area;
|
2008-05-20 15:39:47 +02:00
|
|
|
bool ignore = false;
|
|
|
|
|
2008-09-23 17:20:07 +02:00
|
|
|
globalconf.screens[statusbar->screen].need_arrange = true;
|
|
|
|
|
|
|
|
if(!statusbar->isvisible)
|
2008-09-20 21:24:16 +02:00
|
|
|
{
|
|
|
|
xcb_unmap_window(globalconf.connection, statusbar->sw.window);
|
|
|
|
/* kick out systray if needed */
|
|
|
|
statusbar_systray_refresh(statusbar);
|
|
|
|
return;
|
|
|
|
}
|
2008-01-16 17:47:12 +01:00
|
|
|
|
2008-09-03 22:15:14 +02:00
|
|
|
area = screen_area_get(statusbar->screen, NULL,
|
|
|
|
&globalconf.screens[statusbar->screen].padding, true);
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-09-21 10:13:21 +02:00
|
|
|
/* Top and Bottom wibox_t have prio */
|
2008-09-20 16:45:43 +02:00
|
|
|
for(int i = 0; i < globalconf.screens[statusbar->screen].statusbars.len; i++)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_t *sb = globalconf.screens[statusbar->screen].statusbars.tab[i];
|
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:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.x += statusbar->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
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:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.x -= statusbar->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
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:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.y += sb->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.height -= sb->geometry.height;
|
|
|
|
area.y += sb->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
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:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.y -= sb->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
2008-09-22 19:11:39 +02:00
|
|
|
area.height -= sb->geometry.height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
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:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.height = area.height;
|
|
|
|
statusbar->geometry.width = 1.5 * globalconf.font->height;
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + area.width - statusbar->geometry.width;
|
|
|
|
statusbar->geometry.y = area.y;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + area.width - statusbar->geometry.width;
|
|
|
|
statusbar->geometry.y = area.y + area.height - statusbar->geometry.height;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + area.width - statusbar->geometry.width;
|
|
|
|
statusbar->geometry.y = (area.y + area.height - statusbar->geometry.height) / 2;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
2008-09-04 15:22:42 +02:00
|
|
|
case Left:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.height = area.height;
|
|
|
|
statusbar->geometry.width = 1.5 * globalconf.font->height;
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x;
|
|
|
|
statusbar->geometry.y = (area.y + area.height) - statusbar->geometry.height;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x;
|
|
|
|
statusbar->geometry.y = area.y;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x;
|
|
|
|
statusbar->geometry.y = (area.y + area.height - statusbar->geometry.height) / 2;
|
2008-05-24 11:08:34 +02:00
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
2008-09-04 15:22:42 +02:00
|
|
|
case Bottom:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.width = area.width;
|
|
|
|
statusbar->geometry.height = 1.5 * globalconf.font->height;
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x;
|
|
|
|
statusbar->geometry.y = (area.y + area.height) - statusbar->geometry.height;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + area.width - statusbar->geometry.width;
|
|
|
|
statusbar->geometry.y = (area.y + area.height) - statusbar->geometry.height;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + (area.width - statusbar->geometry.width) / 2;
|
|
|
|
statusbar->geometry.y = (area.y + area.height) - statusbar->geometry.height;
|
2008-09-04 15:22:42 +02:00
|
|
|
break;
|
2008-05-24 11:08:34 +02:00
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
2008-09-04 15:22:42 +02:00
|
|
|
default:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.width = area.width;
|
|
|
|
statusbar->geometry.height = 1.5 * globalconf.font->height;
|
2008-05-24 11:08:34 +02:00
|
|
|
switch(statusbar->align)
|
|
|
|
{
|
|
|
|
default:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x;
|
|
|
|
statusbar->geometry.y = area.y;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + area.width - statusbar->geometry.width;
|
|
|
|
statusbar->geometry.y = area.y;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x = area.x + (area.width - statusbar->geometry.width) / 2;
|
|
|
|
statusbar->geometry.y = area.y;
|
2008-05-24 11:08:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-20 21:24:16 +02:00
|
|
|
if(!statusbar->sw.window)
|
2008-09-04 15:22:42 +02:00
|
|
|
{
|
2008-09-20 16:19:10 +02:00
|
|
|
int phys_screen = screen_virttophys(statusbar->screen);
|
|
|
|
|
2008-09-20 21:24:16 +02:00
|
|
|
simplewindow_init(&statusbar->sw, phys_screen,
|
2008-09-22 19:11:39 +02:00
|
|
|
statusbar->geometry.x, statusbar->geometry.y,
|
|
|
|
statusbar->geometry.width, statusbar->geometry.height,
|
2008-09-20 21:24:16 +02:00
|
|
|
0, statusbar->position,
|
|
|
|
&statusbar->colors.fg, &statusbar->colors.bg);
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->need_update = true;
|
2008-09-20 21:24:16 +02:00
|
|
|
}
|
|
|
|
/* same window size and position ? */
|
|
|
|
else
|
|
|
|
{
|
2008-09-22 19:11:39 +02:00
|
|
|
if(statusbar->geometry.width != statusbar->sw.geometry.width
|
|
|
|
|| statusbar->geometry.height != statusbar->sw.geometry.height)
|
2008-09-20 21:24:16 +02:00
|
|
|
{
|
2008-09-22 19:11:39 +02:00
|
|
|
simplewindow_resize(&statusbar->sw, statusbar->geometry.width, statusbar->geometry.height);
|
2008-09-20 21:24:16 +02:00
|
|
|
statusbar->need_update = true;
|
|
|
|
}
|
2008-09-04 15:22:42 +02:00
|
|
|
|
2008-09-22 19:11:39 +02:00
|
|
|
if(statusbar->geometry.x != statusbar->sw.geometry.x
|
|
|
|
|| statusbar->geometry.y != statusbar->sw.geometry.y)
|
|
|
|
simplewindow_move(&statusbar->sw, statusbar->geometry.x, statusbar->geometry.y);
|
2008-09-04 15:22:42 +02:00
|
|
|
}
|
2008-05-30 10:24:13 +02:00
|
|
|
|
2008-09-23 17:20:07 +02:00
|
|
|
xcb_map_window(globalconf.connection, statusbar->sw.window);
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/** Create a new statusbar (DEPRECATED).
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-09-21 11:42:54 +02:00
|
|
|
* \lparam A table with optionaly defined values:
|
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-09-21 20:39:23 +02:00
|
|
|
deprecate();
|
2008-08-19 18:20:39 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
return luaA_wibox_new(L);
|
2008-07-01 16:31:22 +02:00
|
|
|
}
|
|
|
|
|
2008-07-24 17:37:24 +02:00
|
|
|
/** Remove a statubar from a screen.
|
|
|
|
* \param statusbar Statusbar to detach from screen.
|
|
|
|
*/
|
2008-09-21 20:39:23 +02:00
|
|
|
void
|
|
|
|
statusbar_detach(wibox_t *statusbar)
|
2008-07-24 17:37:24 +02:00
|
|
|
{
|
|
|
|
if(statusbar->screen != SCREEN_UNDEF)
|
|
|
|
{
|
2008-09-23 17:20:07 +02:00
|
|
|
bool v;
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-23 17:20:07 +02:00
|
|
|
/* save visible state */
|
|
|
|
v = statusbar->isvisible;
|
|
|
|
statusbar->isvisible = false;
|
2008-07-24 17:37:24 +02:00
|
|
|
statusbar_position_update(statusbar);
|
|
|
|
/* restore position */
|
2008-09-23 17:20:07 +02:00
|
|
|
statusbar->isvisible = v;
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-20 21:24:16 +02:00
|
|
|
simplewindow_wipe(&statusbar->sw);
|
|
|
|
|
2008-09-20 16:45:43 +02:00
|
|
|
for(int i = 0; i < globalconf.screens[statusbar->screen].statusbars.len; i++)
|
|
|
|
if(globalconf.screens[statusbar->screen].statusbars.tab[i] == statusbar)
|
|
|
|
{
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_array_take(&globalconf.screens[statusbar->screen].statusbars, i);
|
2008-09-20 16:45:43 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-07-24 17:37:24 +02:00
|
|
|
globalconf.screens[statusbar->screen].need_arrange = true;
|
|
|
|
statusbar->screen = SCREEN_UNDEF;
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->type = WIBOX_TYPE_NONE;
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_unref(&statusbar);
|
2008-07-24 17:37:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/** Attach a statusbar.
|
|
|
|
* \param statusbar The statusbar to attach.
|
|
|
|
* \param s The screen to attach the statusbar to.
|
2008-07-01 16:31:22 +02:00
|
|
|
*/
|
2008-09-21 20:39:23 +02:00
|
|
|
void
|
|
|
|
statusbar_attach(wibox_t *statusbar, screen_t *s)
|
2008-07-01 16:31:22 +02:00
|
|
|
{
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar_detach(statusbar);
|
2008-08-08 15:47:09 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->screen = s->index;
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
wibox_array_append(&s->statusbars, wibox_ref(&statusbar));
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->type = WIBOX_TYPE_STATUSBAR;
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/* All the other statusbar and ourselves need to be repositioned */
|
|
|
|
for(int i = 0; i < s->statusbars.len; i++)
|
|
|
|
statusbar_position_update(s->statusbars.tab[i]);
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
ewmh_update_workarea(screen_virttophys(s->index));
|
|
|
|
}
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/** Statusbar newindex.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param statusbar The wibox statusbar.
|
|
|
|
* \param tok The token for property.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_statusbar_newindex(lua_State *L, wibox_t *statusbar, awesome_token_t tok)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *buf;
|
|
|
|
position_t p;
|
2008-07-24 17:37:24 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
switch(tok)
|
|
|
|
{
|
2008-07-01 16:31:22 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
buf = luaL_checklstring(L, 3, &len);
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->align = draw_align_fromstr(buf, len);
|
|
|
|
statusbar_position_update(statusbar);
|
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);
|
2008-09-21 20:39:23 +02:00
|
|
|
if(p != statusbar->position)
|
2008-07-01 17:00:06 +02:00
|
|
|
{
|
2008-09-21 20:39:23 +02:00
|
|
|
statusbar->position = p;
|
|
|
|
simplewindow_wipe(&statusbar->sw);
|
|
|
|
statusbar->sw.window = 0;
|
|
|
|
if(statusbar->screen != SCREEN_UNDEF)
|
2008-08-12 08:22:37 +02:00
|
|
|
{
|
2008-09-21 20:39:23 +02:00
|
|
|
for(int i = 0; i < globalconf.screens[statusbar->screen].statusbars.len; i++)
|
2008-09-20 16:45:43 +02:00
|
|
|
{
|
2008-09-21 20:39:23 +02:00
|
|
|
wibox_t *s = globalconf.screens[statusbar->screen].statusbars.tab[i];
|
2008-08-12 08:22:37 +02:00
|
|
|
statusbar_position_update(s);
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-09-21 20:39:23 +02:00
|
|
|
ewmh_update_workarea(screen_virttophys(statusbar->screen));
|
2008-08-12 08:22:37 +02:00
|
|
|
}
|
2008-07-01 17:00:06 +02:00
|
|
|
}
|
2008-08-08 15:47:09 +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[] =
|
|
|
|
{
|
|
|
|
{ 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
|