2007-10-03 17:26:14 +02:00
|
|
|
/*
|
2007-09-15 15:16:53 +02:00
|
|
|
* draw.c - draw 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-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-09-24 17:08:47 +02:00
|
|
|
#include "layouts/tile.h"
|
2007-09-15 15:16:53 +02:00
|
|
|
|
2007-09-16 16:58:44 +02:00
|
|
|
/** Check if at least a client is tagged with tag number t and is on screen
|
|
|
|
* screen
|
2007-09-15 15:16:53 +02:00
|
|
|
* \param t tag number
|
2007-09-16 16:58:44 +02:00
|
|
|
* \param screen screen number
|
2007-09-15 15:16:53 +02:00
|
|
|
* \return True or False
|
|
|
|
*/
|
|
|
|
static Bool
|
2007-10-11 21:50:32 +02:00
|
|
|
isoccupied(Client **head, unsigned int t, int screen)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
2007-10-11 21:50:32 +02:00
|
|
|
for(c = *head; c; c = c->next)
|
2007-09-16 16:58:44 +02:00
|
|
|
if(c->tags[t] && c->screen == screen)
|
2007-09-15 15:16:53 +02:00
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-15 18:19:33 +02:00
|
|
|
drawstatusbar(awesome_config * awesomeconf)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-10-09 22:35:44 +02:00
|
|
|
int z, i, x = 0, y = 0, w;
|
2007-09-24 17:08:47 +02:00
|
|
|
|
2007-09-15 15:16:53 +02:00
|
|
|
for(i = 0; i < awesomeconf->ntags; i++)
|
|
|
|
{
|
2007-10-15 18:19:33 +02:00
|
|
|
w = textwidth(awesomeconf->display, awesomeconf->font,
|
2007-10-16 01:20:03 +02:00
|
|
|
awesomeconf->tags[i].name);
|
2007-09-24 15:37:52 +02:00
|
|
|
if(awesomeconf->tags[i].selected)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
awesomeconf->tags[i].name, awesomeconf->colors_selected);
|
2007-10-11 21:50:32 +02:00
|
|
|
if(isoccupied(awesomeconf->clients, i, awesomeconf->screen))
|
2007-10-15 18:19:33 +02:00
|
|
|
drawrectangle(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-11 15:44:30 +02:00
|
|
|
x, y,
|
|
|
|
(awesomeconf->font->height + 2) / 4,
|
|
|
|
(awesomeconf->font->height + 2) / 4,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
2007-10-11 23:12:05 +02:00
|
|
|
*awesomeconf->client_sel && (*awesomeconf->client_sel)->tags[i],
|
2007-10-11 15:44:30 +02:00
|
|
|
awesomeconf->colors_selected[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
awesomeconf->tags[i].name, awesomeconf->colors_normal);
|
2007-10-11 21:50:32 +02:00
|
|
|
if(isoccupied(awesomeconf->clients, i, awesomeconf->screen))
|
2007-10-15 18:19:33 +02:00
|
|
|
drawrectangle(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-11 15:44:30 +02:00
|
|
|
x, y,
|
|
|
|
(awesomeconf->font->height + 2) / 4,
|
|
|
|
(awesomeconf->font->height + 2) / 4,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
2007-10-11 23:12:05 +02:00
|
|
|
*awesomeconf->client_sel && (*awesomeconf->client_sel)->tags[i],
|
2007-10-11 15:44:30 +02:00
|
|
|
awesomeconf->colors_normal[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-10-09 22:35:44 +02:00
|
|
|
x += w;
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, awesomeconf->statusbar.txtlayoutwidth,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
awesomeconf->current_layout->symbol, awesomeconf->colors_normal);
|
|
|
|
z = x + awesomeconf->statusbar.txtlayoutwidth;
|
2007-10-16 01:20:03 +02:00
|
|
|
w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext);
|
2007-10-11 16:29:20 +02:00
|
|
|
x = awesomeconf->statusbar.width - w;
|
2007-10-09 22:35:44 +02:00
|
|
|
if(x < z)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-10-09 22:35:44 +02:00
|
|
|
x = z;
|
2007-10-11 16:29:20 +02:00
|
|
|
w = awesomeconf->statusbar.width - z;
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
awesomeconf->statustext, awesomeconf->colors_normal);
|
2007-10-09 22:35:44 +02:00
|
|
|
if((w = x - z) > awesomeconf->statusbar.height)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-10-09 22:35:44 +02:00
|
|
|
x = z;
|
2007-10-11 23:12:05 +02:00
|
|
|
if(*awesomeconf->client_sel)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-11 23:12:05 +02:00
|
|
|
(*awesomeconf->client_sel)->name, awesomeconf->colors_selected);
|
|
|
|
if((*awesomeconf->client_sel)->isfloating)
|
2007-10-15 18:19:33 +02:00
|
|
|
drawcircle(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-11 17:06:55 +02:00
|
|
|
x, y,
|
|
|
|
(awesomeconf->font->height + 2) / 4,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
2007-10-11 23:12:05 +02:00
|
|
|
(*awesomeconf->client_sel)->ismax,
|
2007-10-11 17:06:55 +02:00
|
|
|
awesomeconf->colors_selected[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-10-11 11:33:40 +02:00
|
|
|
else if(IS_ARRANGE(0, layout_tile) || IS_ARRANGE(0, layout_tileleft))
|
2007-09-24 17:08:47 +02:00
|
|
|
{
|
|
|
|
char buf[256];
|
2007-10-08 18:45:05 +02:00
|
|
|
snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact);
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
buf, awesomeconf->colors_normal);
|
2007-09-24 17:08:47 +02:00
|
|
|
}
|
2007-09-15 15:16:53 +02:00
|
|
|
else
|
2007-10-15 18:19:33 +02:00
|
|
|
drawtext(awesomeconf->display, awesomeconf->phys_screen,
|
2007-10-10 19:59:14 +02:00
|
|
|
x, y, w,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.width,
|
|
|
|
awesomeconf->statusbar.height,
|
|
|
|
awesomeconf->font,
|
2007-10-10 19:59:14 +02:00
|
|
|
NULL, awesomeconf->colors_normal);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-10-15 18:19:33 +02:00
|
|
|
XCopyArea(awesomeconf->display, awesomeconf->statusbar.drawable,
|
|
|
|
awesomeconf->statusbar.window, DefaultGC(awesomeconf->display, awesomeconf->phys_screen), 0, 0,
|
2007-10-11 16:29:20 +02:00
|
|
|
awesomeconf->statusbar.width, awesomeconf->statusbar.height, 0, 0);
|
2007-10-15 18:19:33 +02:00
|
|
|
XSync(awesomeconf->display, False);
|
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-10-15 12:06:43 +02:00
|
|
|
initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, XftFont *font, Layout *layouts, int nlayouts)
|
2007-09-15 22:25:49 +02:00
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
2007-10-15 12:06:43 +02:00
|
|
|
int i, phys_screen = get_phys_screen(disp, screen);
|
|
|
|
ScreenInfo *si = get_screen_info(disp, screen, NULL);
|
2007-09-15 22:25:49 +02:00
|
|
|
|
2007-10-11 19:29:34 +02:00
|
|
|
statusbar->width = si[screen].width;
|
2007-10-16 01:20:03 +02:00
|
|
|
statusbar->height = font->height * 1.5;
|
2007-10-11 19:29:34 +02:00
|
|
|
p_delete(&si);
|
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-10-10 13:29:46 +02:00
|
|
|
wa.cursor = cursor;
|
2007-09-15 22:25:49 +02:00
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
2007-10-11 19:29:34 +02:00
|
|
|
statusbar->window = XCreateWindow(disp, RootWindow(disp, phys_screen), 0, 0,
|
|
|
|
statusbar->width,
|
|
|
|
statusbar->height,
|
|
|
|
0, DefaultDepth(disp, phys_screen), CopyFromParent,
|
2007-10-15 12:06:43 +02:00
|
|
|
DefaultVisual(disp, phys_screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
2007-10-10 13:29:46 +02:00
|
|
|
XDefineCursor(disp, statusbar->window, cursor);
|
2007-09-15 22:25:49 +02:00
|
|
|
updatebarpos(disp, *statusbar);
|
|
|
|
XMapRaised(disp, statusbar->window);
|
|
|
|
statusbar->drawable = XCreatePixmap(disp,
|
2007-10-01 15:23:05 +02:00
|
|
|
RootWindow(disp, phys_screen),
|
2007-10-11 19:29:34 +02:00
|
|
|
statusbar->width,
|
2007-09-15 22:25:49 +02:00
|
|
|
statusbar->height,
|
2007-10-01 15:23:05 +02:00
|
|
|
DefaultDepth(disp, phys_screen));
|
2007-10-15 12:06:43 +02:00
|
|
|
|
|
|
|
for(i = 0; i < nlayouts; i++)
|
|
|
|
statusbar->txtlayoutwidth = MAX(statusbar->txtlayoutwidth,
|
2007-10-16 01:20:03 +02:00
|
|
|
(textwidth(disp, font, layouts[i].symbol)));
|
2007-09-15 22:25:49 +02:00
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
updatebarpos(Display *disp, Statusbar statusbar)
|
|
|
|
{
|
|
|
|
XEvent ev;
|
2007-10-01 20:58:29 +02:00
|
|
|
ScreenInfo *si = get_screen_info(disp, statusbar.screen, NULL);
|
2007-09-15 15:26:51 +02:00
|
|
|
|
|
|
|
switch (statusbar.position)
|
|
|
|
{
|
|
|
|
default:
|
2007-09-27 21:22:35 +02:00
|
|
|
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].y_org);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
|
|
|
case BarBot:
|
2007-09-27 21:22:35 +02:00
|
|
|
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].height - statusbar.height);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
|
|
|
case BarOff:
|
2007-09-27 21:22:35 +02:00
|
|
|
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].y_org - statusbar.height);
|
2007-09-15 15:26:51 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 23:44:35 +02:00
|
|
|
p_delete(&si);
|
2007-09-15 15:26:51 +02:00
|
|
|
XSync(disp, False);
|
|
|
|
while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
|
|
|
|
}
|
2007-09-15 15:34:28 +02:00
|
|
|
|
|
|
|
void
|
2007-10-11 23:32:29 +02:00
|
|
|
uicb_togglebar(awesome_config *awesomeconf,
|
2007-09-15 15:34:28 +02:00
|
|
|
const char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
if(awesomeconf->statusbar.position == BarOff)
|
2007-10-08 13:07:01 +02:00
|
|
|
awesomeconf->statusbar.position = (awesomeconf->statusbar_default_position == BarOff) ? BarTop : awesomeconf->statusbar_default_position;
|
2007-09-15 15:34:28 +02:00
|
|
|
else
|
|
|
|
awesomeconf->statusbar.position = BarOff;
|
2007-10-11 23:32:29 +02:00
|
|
|
updatebarpos(awesomeconf->display, awesomeconf->statusbar);
|
2007-10-15 18:23:05 +02:00
|
|
|
arrange(awesomeconf);
|
2007-09-15 15:34:28 +02:00
|
|
|
}
|
|
|
|
|
2007-10-12 17:10:36 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
uicb_setstatustext(awesome_config *awesomeconf, const char *arg)
|
|
|
|
{
|
|
|
|
if(!arg)
|
|
|
|
return;
|
|
|
|
a_strncpy(awesomeconf->statustext, sizeof(awesomeconf->statustext), arg, a_strlen(arg));
|
|
|
|
|
2007-10-15 18:19:33 +02:00
|
|
|
drawstatusbar(awesomeconf);
|
2007-10-12 17:10:36 +02:00
|
|
|
}
|
2007-10-15 13:56:24 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|