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
|
|
|
*/
|
|
|
|
|
2007-09-24 17:08:47 +02:00
|
|
|
#include <stdio.h>
|
2007-11-11 18:59:11 +01:00
|
|
|
#include <math.h>
|
2007-09-24 17:08:47 +02:00
|
|
|
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "statusbar.h"
|
2007-09-15 15:26:51 +02:00
|
|
|
#include "screen.h"
|
2007-12-14 14:29:32 +01:00
|
|
|
#include "tag.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2008-01-23 15:54:30 +01:00
|
|
|
#include "window.h"
|
2007-12-15 03:42:15 +01:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-01-10 20:53:31 +01:00
|
|
|
static void
|
2008-03-19 16:32:37 +01:00
|
|
|
statusbar_position_update(Statusbar *statusbar)
|
2008-01-10 20:53:31 +01:00
|
|
|
{
|
2008-03-19 16:32:37 +01:00
|
|
|
Statusbar *sb;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area;
|
2008-01-10 20:53:31 +01:00
|
|
|
|
2008-03-19 16:32:37 +01:00
|
|
|
if(statusbar->position == Off)
|
|
|
|
{
|
|
|
|
XUnmapWindow(globalconf.display, statusbar->sw->window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-23 15:54:30 +01:00
|
|
|
XMapRaised(globalconf.display, statusbar->sw->window);
|
2008-01-16 17:47:12 +01:00
|
|
|
|
|
|
|
/* Top and Bottom Statusbar have prio */
|
|
|
|
if(statusbar->position == Top || statusbar->position == Bottom)
|
2008-01-29 19:06:44 +01:00
|
|
|
area = screen_get_area(statusbar->screen,
|
2008-01-16 17:47:12 +01:00
|
|
|
NULL,
|
|
|
|
&globalconf.screens[statusbar->screen].padding);
|
|
|
|
else
|
2008-03-19 16:32:37 +01:00
|
|
|
area = screen_get_area(statusbar->screen,
|
|
|
|
globalconf.screens[statusbar->screen].statusbar,
|
|
|
|
&globalconf.screens[statusbar->screen].padding);
|
|
|
|
|
|
|
|
for(sb = globalconf.screens[statusbar->screen].statusbar; sb && sb != statusbar; sb = sb->next)
|
|
|
|
switch(sb->position)
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
if(sb->position == statusbar->position)
|
|
|
|
area.y += sb->height;
|
|
|
|
break;
|
|
|
|
case Bottom:
|
|
|
|
if(sb->position == statusbar->position)
|
|
|
|
area.height -= sb->height;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
/* we need to re-add our own value removed in the
|
|
|
|
* screen_get_area computation */
|
|
|
|
if(statusbar->position == Left
|
|
|
|
|| statusbar->position == Right)
|
|
|
|
{
|
|
|
|
area.x -= statusbar->sw->geometry.width;
|
|
|
|
area.width += statusbar->sw->geometry.width;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
if(statusbar->position == Left
|
|
|
|
|| statusbar->position == Right)
|
|
|
|
area.width += statusbar->sw->geometry.width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 17:47:12 +01:00
|
|
|
|
2008-01-10 20:53:31 +01:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
2008-01-16 17:47:12 +01:00
|
|
|
case Top:
|
2008-01-23 16:10:05 +01:00
|
|
|
simplewindow_move(statusbar->sw, area.x, area.y);
|
2008-01-10 20:53:31 +01:00
|
|
|
break;
|
2008-01-16 17:47:12 +01:00
|
|
|
case Bottom:
|
2008-01-23 17:18:49 +01:00
|
|
|
simplewindow_move(statusbar->sw, area.x, (area.y + area.height) - statusbar->sw->geometry.height);
|
2008-01-10 20:53:31 +01:00
|
|
|
break;
|
2008-01-16 17:47:12 +01:00
|
|
|
case Left:
|
2008-01-24 23:25:12 +01:00
|
|
|
simplewindow_move(statusbar->sw, area.x - statusbar->sw->geometry.width,
|
|
|
|
(area.y + area.height) - statusbar->sw->geometry.height);
|
2008-01-10 20:53:31 +01:00
|
|
|
break;
|
2008-01-16 17:47:12 +01:00
|
|
|
case Right:
|
2008-01-23 16:10:05 +01:00
|
|
|
simplewindow_move(statusbar->sw, area.x + area.width, area.y);
|
2008-01-10 20:53:31 +01:00
|
|
|
break;
|
2008-03-14 17:33:10 +01:00
|
|
|
default:
|
2008-01-10 20:53:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 21:50:14 +01:00
|
|
|
static void
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_draw(Statusbar *statusbar)
|
2007-12-15 03:42:15 +01:00
|
|
|
{
|
2008-02-08 10:59:55 +01:00
|
|
|
Widget *widget;
|
2007-12-15 07:53:53 +01:00
|
|
|
int left = 0, right = 0;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t rectangle = { 0, 0, 0, 0, NULL, NULL };
|
2008-01-07 18:12:38 +01:00
|
|
|
|
2008-01-12 23:38:31 +01:00
|
|
|
rectangle.width = statusbar->width;
|
|
|
|
rectangle.height = statusbar->height;
|
2008-03-21 18:02:40 +01:00
|
|
|
draw_rectangle(statusbar->ctx, rectangle, 1.0, True,
|
2008-03-14 08:35:06 +01:00
|
|
|
globalconf.screens[statusbar->screen].styles.normal.bg);
|
2007-12-30 21:00:34 +01:00
|
|
|
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2007-12-15 07:53:53 +01:00
|
|
|
if (widget->alignment == AlignLeft)
|
2008-01-07 18:12:38 +01:00
|
|
|
{
|
|
|
|
widget->cache.needs_update = False;
|
2008-03-20 09:08:15 +01:00
|
|
|
left += widget->draw(widget, statusbar->ctx, left, (left + right));
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
2007-12-22 16:49:21 +01:00
|
|
|
|
|
|
|
/* renders right widget from last to first */
|
2008-02-08 10:59:55 +01:00
|
|
|
for(widget = *widget_list_last(&statusbar->widgets);
|
|
|
|
widget;
|
|
|
|
widget = widget_list_prev(&statusbar->widgets, widget))
|
|
|
|
if (widget->alignment == AlignRight)
|
2007-12-22 16:49:21 +01:00
|
|
|
{
|
2008-01-07 18:12:38 +01:00
|
|
|
widget->cache.needs_update = False;
|
2008-03-20 09:08:15 +01:00
|
|
|
right += widget->draw(widget, statusbar->ctx, right, (left + right));
|
2007-12-22 16:49:21 +01:00
|
|
|
}
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2007-12-15 07:53:53 +01:00
|
|
|
if (widget->alignment == AlignFlex)
|
2008-01-07 18:12:38 +01:00
|
|
|
{
|
|
|
|
widget->cache.needs_update = False;
|
2008-03-20 09:08:15 +01:00
|
|
|
left += widget->draw(widget, statusbar->ctx, left, (left + right));
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
2007-12-15 03:42:15 +01:00
|
|
|
|
2008-01-23 17:44:07 +01:00
|
|
|
switch(statusbar->position)
|
2007-12-30 12:33:57 +01:00
|
|
|
{
|
2008-01-23 17:44:07 +01:00
|
|
|
case Right:
|
2008-03-20 09:17:34 +01:00
|
|
|
draw_rotate(statusbar->ctx, statusbar->sw->drawable,
|
|
|
|
statusbar->ctx->height, statusbar->ctx->width,
|
|
|
|
M_PI_2, statusbar->height, 0);
|
2008-01-23 17:44:07 +01:00
|
|
|
break;
|
|
|
|
case Left:
|
2008-03-20 09:17:34 +01:00
|
|
|
draw_rotate(statusbar->ctx, statusbar->sw->drawable,
|
|
|
|
statusbar->ctx->height, statusbar->ctx->width,
|
|
|
|
- M_PI_2, 0, statusbar->width);
|
2008-01-23 17:44:07 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2007-12-30 12:33:57 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_display(statusbar);
|
2007-12-30 12:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_display(Statusbar *statusbar)
|
2007-12-30 12:33:57 +01:00
|
|
|
{
|
2007-12-30 14:23:01 +01:00
|
|
|
/* don't waste our time */
|
2008-01-24 20:22:39 +01:00
|
|
|
if(statusbar->position != Off)
|
2008-03-21 10:53:17 +01:00
|
|
|
simplewindow_refresh_drawable(statusbar->sw, statusbar->phys_screen);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
2007-09-15 22:25:49 +02:00
|
|
|
void
|
2008-01-16 17:50:37 +01:00
|
|
|
statusbar_preinit(Statusbar *statusbar)
|
2007-09-15 22:25:49 +02:00
|
|
|
{
|
2007-12-30 18:54:17 +01:00
|
|
|
if(statusbar->height <= 0)
|
2008-03-14 08:35:06 +01:00
|
|
|
/* 1.5 as default factor, it fits nice but no one knows why */
|
|
|
|
statusbar->height = 1.5 * MAX(globalconf.screens[statusbar->screen].styles.normal.font->height,
|
|
|
|
MAX(globalconf.screens[statusbar->screen].styles.focus.font->height,
|
|
|
|
globalconf.screens[statusbar->screen].styles.urgent.font->height));
|
2008-01-16 17:47:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
statusbar_init(Statusbar *statusbar)
|
|
|
|
{
|
|
|
|
Statusbar *sb;
|
2008-03-20 09:08:15 +01:00
|
|
|
Drawable dw;
|
2008-03-21 10:53:17 +01:00
|
|
|
int phys_screen = screen_virttophys(statusbar->screen);
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area = screen_get_area(statusbar->screen,
|
2008-01-16 17:47:12 +01:00
|
|
|
globalconf.screens[statusbar->screen].statusbar,
|
|
|
|
&globalconf.screens[statusbar->screen].padding);
|
|
|
|
|
2008-03-21 10:53:17 +01:00
|
|
|
statusbar->phys_screen = phys_screen;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-01-16 17:47:12 +01:00
|
|
|
/* Top and Bottom Statusbar have prio */
|
|
|
|
for(sb = globalconf.screens[statusbar->screen].statusbar; sb; sb = sb->next)
|
|
|
|
switch(sb->position)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
area.width += sb->height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-12-29 15:47:28 +01:00
|
|
|
|
2007-12-30 18:55:46 +01:00
|
|
|
if(statusbar->width <= 0)
|
|
|
|
{
|
2008-01-04 19:12:07 +01:00
|
|
|
if(statusbar->position == Right || statusbar->position == Left)
|
2007-12-30 18:55:46 +01:00
|
|
|
statusbar->width = area.height;
|
|
|
|
else
|
|
|
|
statusbar->width = area.width;
|
|
|
|
}
|
2007-09-27 21:22:35 +02:00
|
|
|
|
2008-03-19 16:32:37 +01:00
|
|
|
switch(statusbar->position)
|
2008-01-24 10:37:16 +01:00
|
|
|
{
|
|
|
|
case Right:
|
|
|
|
case Left:
|
|
|
|
statusbar->sw =
|
2008-01-26 17:58:01 +01:00
|
|
|
simplewindow_new(globalconf.display, phys_screen, 0, 0,
|
|
|
|
statusbar->height, statusbar->width, 0);
|
2008-01-24 10:37:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusbar->sw =
|
2008-01-26 17:58:01 +01:00
|
|
|
simplewindow_new(globalconf.display, phys_screen, 0, 0,
|
|
|
|
statusbar->width, statusbar->height, 0);
|
2008-01-24 10:37:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_calculate_alignments(statusbar->widgets);
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2008-03-19 16:32:37 +01:00
|
|
|
statusbar_position_update(statusbar);
|
2007-12-31 10:04:03 +01:00
|
|
|
|
2008-03-20 09:08:15 +01:00
|
|
|
switch(statusbar->position)
|
|
|
|
{
|
|
|
|
case Off:
|
|
|
|
return;
|
|
|
|
case Right:
|
|
|
|
case Left:
|
|
|
|
/* we need a new pixmap this way [ ] to render */
|
|
|
|
dw = XCreatePixmap(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, phys_screen),
|
|
|
|
statusbar->width, statusbar->height,
|
|
|
|
DefaultDepth(globalconf.display, phys_screen));
|
|
|
|
statusbar->ctx = draw_context_new(globalconf.display,
|
|
|
|
phys_screen,
|
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
|
|
|
dw);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusbar->ctx = draw_context_new(globalconf.display,
|
|
|
|
phys_screen,
|
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
|
|
|
statusbar->sw->drawable);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-31 10:04:03 +01:00
|
|
|
statusbar_draw(statusbar);
|
2007-09-15 22:25:49 +02:00
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
2008-01-07 18:12:38 +01:00
|
|
|
void
|
|
|
|
statusbar_refresh()
|
|
|
|
{
|
|
|
|
int screen;
|
|
|
|
Statusbar *statusbar;
|
|
|
|
Widget *widget;
|
|
|
|
|
2008-03-13 09:28:21 +01:00
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
2008-01-07 18:12:38 +01:00
|
|
|
for(statusbar = globalconf.screens[screen].statusbar;
|
|
|
|
statusbar;
|
|
|
|
statusbar = statusbar->next)
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
|
|
|
if(widget->cache.needs_update)
|
|
|
|
{
|
|
|
|
statusbar_draw(statusbar);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-03 14:00:46 +02:00
|
|
|
Statusbar *
|
|
|
|
statusbar_getbyname(int screen, const char *name)
|
2007-12-30 21:00:34 +01:00
|
|
|
{
|
|
|
|
Statusbar *sb;
|
|
|
|
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
if(!a_strcmp(sb->name, name))
|
|
|
|
return sb;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
statusbar_toggle(Statusbar *statusbar)
|
2007-09-15 15:34:28 +02:00
|
|
|
{
|
2008-01-04 19:12:07 +01:00
|
|
|
if(statusbar->position == Off)
|
|
|
|
statusbar->position = (statusbar->dposition == Off) ? Top : statusbar->dposition;
|
2007-09-15 15:34:28 +02:00
|
|
|
else
|
2008-01-04 19:12:07 +01:00
|
|
|
statusbar->position = Off;
|
2008-03-19 16:32:37 +01:00
|
|
|
|
2008-01-18 09:34:52 +01:00
|
|
|
globalconf.screens[statusbar->screen].need_arrange = True;
|
2007-09-15 15:34:28 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
/** Toggle statusbar
|
2007-12-19 04:39:59 +01:00
|
|
|
* \param screen Screen ID
|
2008-01-07 18:12:38 +01:00
|
|
|
* \param arg statusbar name
|
2007-12-19 04:39:59 +01:00
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-12-14 15:52:52 +01:00
|
|
|
void
|
2007-12-30 21:00:34 +01:00
|
|
|
uicb_statusbar_toggle(int screen, char *arg)
|
2007-12-14 15:52:52 +01:00
|
|
|
{
|
2008-04-03 14:00:46 +02:00
|
|
|
Statusbar *sb = statusbar_getbyname(screen, arg);
|
2007-12-30 21:00:34 +01:00
|
|
|
|
|
|
|
if(sb)
|
|
|
|
statusbar_toggle(sb);
|
|
|
|
else
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
statusbar_toggle(sb);
|
2008-03-19 16:32:37 +01:00
|
|
|
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
statusbar_position_update(sb);
|
2007-12-14 15:52:52 +01:00
|
|
|
}
|
2007-10-12 17:10:36 +02:00
|
|
|
|
2008-03-19 16:32:37 +01:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|