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
|
|
|
*
|
|
|
|
* Copyright © 2007 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.
|
|
|
|
*
|
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 "layout.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "draw.h"
|
2007-09-15 15:26:51 +02:00
|
|
|
#include "screen.h"
|
|
|
|
#include "util.h"
|
2007-12-14 14:29:32 +01:00
|
|
|
#include "tag.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.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
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
static void
|
|
|
|
statusbar_draw(Statusbar *statusbar)
|
2007-12-15 03:42:15 +01:00
|
|
|
{
|
2007-12-30 21:00:34 +01:00
|
|
|
int phys_screen = get_phys_screen(statusbar->screen);
|
2007-12-22 16:49:21 +01:00
|
|
|
Widget *widget, *last_drawn = NULL;
|
2007-12-15 07:53:53 +01:00
|
|
|
int left = 0, right = 0;
|
2007-12-15 03:42:15 +01:00
|
|
|
|
|
|
|
/* don't waste our time */
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarOff)
|
2007-12-15 03:42:15 +01:00
|
|
|
return;
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
XFreePixmap(globalconf.display, statusbar->drawable);
|
2007-12-30 18:13:33 +01:00
|
|
|
|
2007-12-30 12:33:57 +01:00
|
|
|
DrawCtx *ctx = draw_get_context(phys_screen,
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->width,
|
|
|
|
statusbar->height);
|
|
|
|
|
|
|
|
draw_rectangle(ctx, 0, 0, statusbar->width, statusbar->height, True,
|
|
|
|
globalconf.screens[statusbar->screen].colors_normal[ColBG]);
|
|
|
|
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2007-12-15 07:53:53 +01:00
|
|
|
if (widget->alignment == AlignLeft)
|
2007-12-16 04:28:29 +01:00
|
|
|
left += widget->draw(widget, ctx, left, (left + right));
|
2007-12-22 16:49:21 +01:00
|
|
|
|
|
|
|
/* renders right widget from last to first */
|
2007-12-30 21:00:34 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2007-12-22 16:49:21 +01:00
|
|
|
if (widget->alignment == AlignRight && last_drawn == widget->next)
|
|
|
|
{
|
2007-12-16 04:28:29 +01:00
|
|
|
right += widget->draw(widget, ctx, right, (left + right));
|
2007-12-22 16:49:21 +01:00
|
|
|
last_drawn = widget;
|
2007-12-30 21:00:34 +01:00
|
|
|
widget = statusbar->widgets;
|
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)
|
2007-12-16 04:28:29 +01:00
|
|
|
left += widget->draw(widget, ctx, left, (left + right));
|
2007-12-15 03:42:15 +01:00
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarRight
|
|
|
|
|| statusbar->position == BarLeft)
|
2007-11-11 18:59:11 +01:00
|
|
|
{
|
2007-11-11 22:27:00 +01:00
|
|
|
Drawable d;
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarRight)
|
|
|
|
d = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0);
|
2007-11-11 19:49:42 +01:00
|
|
|
else
|
2007-12-30 21:00:34 +01:00
|
|
|
d = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width);
|
2007-12-30 12:33:57 +01:00
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->drawable = d;
|
2007-12-30 12:33:57 +01:00
|
|
|
draw_free_context(ctx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->drawable = ctx->drawable;
|
2007-12-30 12:33:57 +01:00
|
|
|
/* just delete the struct, don't delete the drawable */
|
|
|
|
p_delete(&ctx);
|
|
|
|
}
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_display(statusbar);
|
2007-12-30 12:33:57 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
void
|
|
|
|
statusbar_draw_all(int screen)
|
|
|
|
{
|
|
|
|
Statusbar *statusbar;
|
|
|
|
|
|
|
|
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
|
|
|
|
statusbar_draw(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 21:00:34 +01:00
|
|
|
int phys_screen = get_phys_screen(statusbar->screen);
|
2007-12-30 12:33:57 +01:00
|
|
|
|
2007-12-30 14:23:01 +01:00
|
|
|
/* don't waste our time */
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarOff)
|
2007-12-30 14:23:01 +01:00
|
|
|
return;
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarRight
|
|
|
|
|| statusbar->position == BarLeft)
|
|
|
|
XCopyArea(globalconf.display, statusbar->drawable,
|
|
|
|
statusbar->window,
|
2007-12-16 02:45:38 +01:00
|
|
|
DefaultGC(globalconf.display, phys_screen), 0, 0,
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->height,
|
|
|
|
statusbar->width, 0, 0);
|
2007-11-11 18:59:11 +01:00
|
|
|
else
|
2007-12-30 21:00:34 +01:00
|
|
|
XCopyArea(globalconf.display, statusbar->drawable,
|
|
|
|
statusbar->window,
|
2007-12-16 02:45:38 +01:00
|
|
|
DefaultGC(globalconf.display, phys_screen), 0, 0,
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->width, statusbar->height, 0, 0);
|
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
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_init(Statusbar *statusbar, int screen)
|
2007-09-15 22:25:49 +02:00
|
|
|
{
|
2007-12-29 15:47:28 +01:00
|
|
|
Widget *widget;
|
2007-09-15 22:25:49 +02:00
|
|
|
XSetWindowAttributes wa;
|
2007-12-18 09:02:08 +01:00
|
|
|
int phys_screen = get_phys_screen(screen);
|
2007-12-30 21:00:34 +01:00
|
|
|
Area area = get_screen_area(statusbar->screen,
|
2007-12-23 00:54:59 +01:00
|
|
|
NULL,
|
|
|
|
&globalconf.screens[screen].padding);
|
2007-09-15 22:25:49 +02:00
|
|
|
|
2007-12-30 18:54:17 +01:00
|
|
|
if(statusbar->height <= 0)
|
|
|
|
{
|
|
|
|
/* 1.5 as default factor, it fits nice but no one know why */
|
|
|
|
statusbar->height = globalconf.screens[screen].font->height * 1.5;
|
2007-11-11 18:59:11 +01:00
|
|
|
|
2007-12-30 18:54:17 +01:00
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
|
|
|
if(widget->font)
|
|
|
|
statusbar->height = MAX(statusbar->height, widget->font->height * 1.5);
|
|
|
|
}
|
2007-12-29 15:47:28 +01:00
|
|
|
|
2007-12-30 18:55:46 +01:00
|
|
|
if(statusbar->width <= 0)
|
|
|
|
{
|
|
|
|
if(statusbar->position == BarRight || statusbar->position == BarLeft)
|
|
|
|
statusbar->width = area.height;
|
|
|
|
else
|
|
|
|
statusbar->width = area.width;
|
|
|
|
}
|
2007-09-27 21:22:35 +02:00
|
|
|
|
2007-10-15 12:06:43 +02:00
|
|
|
statusbar->screen = screen;
|
|
|
|
|
2007-09-15 22:25:49 +02:00
|
|
|
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
|
|
|
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
|
2007-12-19 05:16:49 +01:00
|
|
|
wa.cursor = globalconf.cursor[CurNormal];
|
2007-09-15 22:25:49 +02:00
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
2007-11-11 18:59:11 +01:00
|
|
|
if(statusbar->dposition == BarRight || statusbar->dposition == BarLeft)
|
2007-12-19 05:16:49 +01:00
|
|
|
statusbar->window = XCreateWindow(globalconf.display,
|
|
|
|
RootWindow(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
0, 0,
|
2007-11-11 18:59:11 +01:00
|
|
|
statusbar->height,
|
|
|
|
statusbar->width,
|
2007-12-19 05:16:49 +01:00
|
|
|
0,
|
|
|
|
DefaultDepth(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
CopyFromParent,
|
|
|
|
DefaultVisual(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
CWOverrideRedirect |
|
|
|
|
CWBackPixmap |
|
|
|
|
CWEventMask,
|
|
|
|
&wa);
|
2007-11-11 18:59:11 +01:00
|
|
|
else
|
2007-12-19 05:16:49 +01:00
|
|
|
statusbar->window = XCreateWindow(globalconf.display,
|
|
|
|
RootWindow(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
0, 0,
|
2007-11-11 18:59:11 +01:00
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
2007-12-19 05:16:49 +01:00
|
|
|
0,
|
|
|
|
DefaultDepth(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
CopyFromParent,
|
|
|
|
DefaultVisual(globalconf.display,
|
|
|
|
phys_screen),
|
|
|
|
CWOverrideRedirect |
|
|
|
|
CWBackPixmap |
|
|
|
|
CWEventMask,
|
|
|
|
&wa);
|
2007-12-30 12:26:11 +01:00
|
|
|
|
|
|
|
statusbar->drawable = XCreatePixmap(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, phys_screen),
|
|
|
|
statusbar->width, statusbar->height,
|
|
|
|
DefaultDepth(globalconf.display, phys_screen));
|
|
|
|
|
|
|
|
|
2007-12-19 05:16:49 +01:00
|
|
|
XDefineCursor(globalconf.display,
|
|
|
|
statusbar->window,
|
|
|
|
globalconf.cursor[CurNormal]);
|
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
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_update_position(statusbar);
|
2007-12-19 05:16:49 +01:00
|
|
|
XMapRaised(globalconf.display, statusbar->window);
|
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
|
|
|
|
|
|
|
void
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_update_position(Statusbar *statusbar)
|
2007-09-15 15:26:51 +02:00
|
|
|
{
|
|
|
|
XEvent ev;
|
2007-12-23 00:54:59 +01:00
|
|
|
Area area = get_screen_area(statusbar->screen,
|
|
|
|
NULL,
|
2007-12-30 21:00:34 +01:00
|
|
|
&globalconf.screens[statusbar->screen].padding);
|
2007-09-15 15:26:51 +02:00
|
|
|
|
2007-12-19 05:40:03 +01:00
|
|
|
XMapRaised(globalconf.display, statusbar->window);
|
2007-12-30 21:00:34 +01:00
|
|
|
switch(statusbar->position)
|
2007-09-15 15:26:51 +02:00
|
|
|
{
|
|
|
|
default:
|
2007-12-19 05:40:03 +01:00
|
|
|
XMoveWindow(globalconf.display,
|
|
|
|
statusbar->window,
|
2007-12-23 00:54:59 +01:00
|
|
|
area.x,
|
|
|
|
area.y);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
2007-11-11 18:59:11 +01:00
|
|
|
case BarRight:
|
2007-12-19 05:40:03 +01:00
|
|
|
XMoveWindow(globalconf.display,
|
|
|
|
statusbar->window,
|
2007-12-23 00:54:59 +01:00
|
|
|
area.x + (area.width - statusbar->height),
|
|
|
|
area.y);
|
2007-11-11 18:59:11 +01:00
|
|
|
break;
|
2007-09-15 15:26:51 +02:00
|
|
|
case BarBot:
|
2007-12-19 05:40:03 +01:00
|
|
|
XMoveWindow(globalconf.display,
|
|
|
|
statusbar->window,
|
2007-12-23 00:54:59 +01:00
|
|
|
area.x,
|
|
|
|
area.height - statusbar->height);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
|
|
|
case BarOff:
|
2007-12-19 05:40:03 +01:00
|
|
|
XUnmapWindow(globalconf.display, statusbar->window);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-12-19 05:40:03 +01:00
|
|
|
XSync(globalconf.display, False);
|
|
|
|
while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
|
2007-09-15 15:26:51 +02:00
|
|
|
}
|
2007-09-15 15:34:28 +02:00
|
|
|
|
2007-12-14 15:52:52 +01:00
|
|
|
int
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar_get_position_from_str(const char *pos)
|
2007-12-14 15:52:52 +01:00
|
|
|
{
|
|
|
|
if(!a_strncmp(pos, "off", 3))
|
|
|
|
return BarOff;
|
|
|
|
else if(!a_strncmp(pos, "bottom", 6))
|
|
|
|
return BarBot;
|
|
|
|
else if(!a_strncmp(pos, "right", 5))
|
|
|
|
return BarRight;
|
|
|
|
else if(!a_strncmp(pos, "left", 4))
|
|
|
|
return BarLeft;
|
|
|
|
return BarTop;
|
|
|
|
}
|
|
|
|
|
2007-12-30 21:00:34 +01:00
|
|
|
static Statusbar *
|
|
|
|
get_statusbar_byname(int screen, const char *name)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2007-12-30 21:00:34 +01:00
|
|
|
if(statusbar->position == BarOff)
|
|
|
|
statusbar->position = (statusbar->dposition == BarOff) ? BarTop : statusbar->dposition;
|
2007-09-15 15:34:28 +02:00
|
|
|
else
|
2007-12-30 21:00:34 +01:00
|
|
|
statusbar->position = BarOff;
|
|
|
|
|
|
|
|
statusbar_update_position(statusbar);
|
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
|
2007-12-30 21:00:34 +01:00
|
|
|
* \param arg Unused
|
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
|
|
|
{
|
2007-12-30 21:00:34 +01:00
|
|
|
Statusbar *sb = get_statusbar_byname(screen, arg);
|
|
|
|
|
|
|
|
if(sb)
|
|
|
|
statusbar_toggle(sb);
|
|
|
|
else
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
statusbar_toggle(sb);
|
|
|
|
|
|
|
|
arrange(screen);
|
2007-12-14 15:52:52 +01:00
|
|
|
}
|
2007-10-12 17:10:36 +02:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|