2008-03-15 13:59:04 +01:00
|
|
|
/*
|
|
|
|
* titlebar.c - titlebar management
|
|
|
|
*
|
|
|
|
* Copyright © 2008 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
|
2008-03-15 20:10:09 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2008-03-15 13:59:04 +01:00
|
|
|
#include "titlebar.h"
|
2008-04-28 12:55:11 +02:00
|
|
|
#include "client.h"
|
2008-03-17 08:56:17 +01:00
|
|
|
#include "screen.h"
|
2008-04-04 10:26:46 +02:00
|
|
|
#include "layouts/floating.h"
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-04-23 17:44:09 +02:00
|
|
|
static char *
|
|
|
|
titlebar_text(client_t *c)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
if(globalconf.focus->client == c)
|
|
|
|
text = c->titlebar.text_focus;
|
|
|
|
else if(c->isurgent)
|
|
|
|
text = c->titlebar.text_urgent;
|
|
|
|
else
|
|
|
|
text = c->titlebar.text_normal;
|
|
|
|
|
2008-04-28 12:23:10 +02:00
|
|
|
return client_markup_parse(c, text, a_strlen(text));
|
2008-04-23 17:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline area_t
|
|
|
|
titlebar_size(client_t *c)
|
|
|
|
{
|
|
|
|
return draw_text_extents(globalconf.connection, globalconf.default_screen,
|
2008-05-20 15:39:47 +02:00
|
|
|
globalconf.font, titlebar_text(c));
|
2008-03-25 14:45:13 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
/** Draw the titlebar content.
|
|
|
|
* \param c the client
|
|
|
|
*/
|
2008-03-15 13:59:04 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
titlebar_draw(client_t *c)
|
2008-03-15 13:59:04 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_drawable_t dw = 0;
|
2008-04-28 15:32:30 +02:00
|
|
|
draw_context_t *ctx;
|
2008-03-15 13:59:04 +01:00
|
|
|
area_t geometry;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_screen_t *s;
|
2008-04-23 17:44:09 +02:00
|
|
|
char *text;
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
if(!c->titlebar_sw)
|
2008-03-15 20:10:09 +01:00
|
|
|
return;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
s = xcb_aux_get_screen(globalconf.connection,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->phys_screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-03-15 20:10:09 +01:00
|
|
|
switch(c->titlebar.position)
|
|
|
|
{
|
|
|
|
case Off:
|
2008-03-15 13:59:04 +01:00
|
|
|
return;
|
2008-03-15 20:10:09 +01:00
|
|
|
case Right:
|
|
|
|
case Left:
|
2008-03-21 16:50:17 +01:00
|
|
|
dw = xcb_generate_id(globalconf.connection);
|
|
|
|
xcb_create_pixmap(globalconf.connection, s->root_depth,
|
|
|
|
dw,
|
2008-03-27 16:05:37 +01:00
|
|
|
s->root,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.height,
|
|
|
|
c->titlebar_sw->geometry.width);
|
|
|
|
ctx = draw_context_new(globalconf.connection, c->titlebar_sw->phys_screen,
|
|
|
|
c->titlebar_sw->geometry.height,
|
|
|
|
c->titlebar_sw->geometry.width,
|
2008-03-20 09:51:01 +01:00
|
|
|
dw);
|
2008-05-20 15:39:47 +02:00
|
|
|
geometry.width = c->titlebar_sw->geometry.height;
|
|
|
|
geometry.height = c->titlebar_sw->geometry.width;
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-05-20 15:39:47 +02:00
|
|
|
ctx = draw_context_new(globalconf.connection, c->titlebar_sw->phys_screen,
|
|
|
|
c->titlebar_sw->geometry.width,
|
|
|
|
c->titlebar_sw->geometry.height,
|
|
|
|
c->titlebar_sw->drawable);
|
|
|
|
geometry = c->titlebar_sw->geometry;
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-04-23 17:44:09 +02:00
|
|
|
text = titlebar_text(c);
|
2008-03-15 13:59:04 +01:00
|
|
|
geometry.x = geometry.y = 0;
|
2008-05-20 15:39:47 +02:00
|
|
|
draw_rectangle(ctx, geometry, 1.0, true, globalconf.colors.bg);
|
|
|
|
draw_text(ctx, globalconf.font, &globalconf.colors.fg, geometry, text);
|
2008-04-23 17:44:09 +02:00
|
|
|
p_delete(&text);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-03-15 20:10:09 +01:00
|
|
|
switch(c->titlebar.position)
|
|
|
|
{
|
|
|
|
case Left:
|
2008-05-30 17:53:10 +02:00
|
|
|
draw_rotate(ctx, ctx->drawable, c->titlebar_sw->drawable,
|
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
2008-05-20 15:39:47 +02:00
|
|
|
- M_PI_2, 0, c->titlebar_sw->geometry.height);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_free_pixmap(globalconf.connection, dw);
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-05-30 17:53:10 +02:00
|
|
|
draw_rotate(ctx, ctx->drawable, c->titlebar_sw->drawable,
|
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
2008-05-20 15:39:47 +02:00
|
|
|
M_PI_2, c->titlebar_sw->geometry.width, 0);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_free_pixmap(globalconf.connection, dw);
|
2008-03-15 20:10:09 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_refresh_drawable(c->titlebar_sw);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-03-21 11:26:56 +01:00
|
|
|
draw_context_delete(&ctx);
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
/** Update the titlebar geometry for a floating client.
|
|
|
|
* \param c the client
|
|
|
|
*/
|
2008-03-15 15:24:47 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
titlebar_update_geometry_floating(client_t *c)
|
2008-03-15 15:24:47 +01:00
|
|
|
{
|
2008-03-24 17:42:45 +01:00
|
|
|
int width, x_offset = 0, y_offset = 0;
|
2008-03-24 16:31:02 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
if(!c->titlebar_sw)
|
2008-03-15 16:41:59 +01:00
|
|
|
return;
|
|
|
|
|
2008-03-15 15:24:47 +01:00
|
|
|
switch(c->titlebar.position)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return;
|
2008-04-04 10:26:46 +02:00
|
|
|
case Off:
|
|
|
|
return;
|
2008-03-15 15:24:47 +01:00
|
|
|
case Top:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
else
|
|
|
|
width = MIN(c->titlebar.width, c->geometry.width);
|
2008-03-24 17:42:45 +01:00
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
x_offset = 2 * c->border + c->geometry.width - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (c->geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-24 17:42:45 +01:00
|
|
|
c->geometry.x + x_offset,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->geometry.y - c->titlebar_sw->geometry.height,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.height);
|
2008-03-15 15:24:47 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
else
|
|
|
|
width = MIN(c->titlebar.width, c->geometry.width);
|
2008-03-24 17:42:45 +01:00
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
x_offset = 2 * c->border + c->geometry.width - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (c->geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-24 17:42:45 +01:00
|
|
|
c->geometry.x + x_offset,
|
2008-03-15 15:24:47 +01:00
|
|
|
c->geometry.y + c->geometry.height + 2 * c->border,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.height);
|
2008-03-15 15:24:47 +01:00
|
|
|
break;
|
2008-03-15 20:10:09 +01:00
|
|
|
case Left:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
|
|
|
width = c->geometry.height + 2 * c->border;
|
|
|
|
else
|
|
|
|
width = MIN(c->titlebar.width, c->geometry.height);
|
2008-03-24 17:42:45 +01:00
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
y_offset = 2 * c->border + c->geometry.height - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (c->geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
|
|
|
c->geometry.x - c->titlebar_sw->geometry.width,
|
2008-03-24 17:42:45 +01:00
|
|
|
c->geometry.y + y_offset,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.width,
|
2008-03-24 16:31:02 +01:00
|
|
|
width);
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
|
|
|
width = c->geometry.height + 2 * c->border;
|
|
|
|
else
|
|
|
|
width = MIN(c->titlebar.width, c->geometry.height);
|
2008-03-24 17:42:45 +01:00
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
y_offset = 2 * c->border + c->geometry.height - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (c->geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-16 18:00:49 +01:00
|
|
|
c->geometry.x + c->geometry.width + 2 * c->border,
|
2008-03-24 17:42:45 +01:00
|
|
|
c->geometry.y + y_offset,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.width,
|
2008-03-24 16:31:02 +01:00
|
|
|
width);
|
2008-03-16 18:00:49 +01:00
|
|
|
break;
|
2008-03-15 15:24:47 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
2008-03-15 15:24:47 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
|
|
|
|
/** Update the titlebar geometry for a tiled client.
|
|
|
|
* \param c the client
|
|
|
|
* \param geometry the geometry the client will receive
|
|
|
|
*/
|
2008-03-26 10:57:06 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
titlebar_update_geometry(client_t *c, area_t geometry)
|
2008-03-15 13:59:04 +01:00
|
|
|
{
|
2008-03-24 17:42:45 +01:00
|
|
|
int width, x_offset = 0 , y_offset = 0;
|
2008-03-24 16:31:02 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
if(!c->titlebar_sw)
|
2008-03-26 10:57:06 +01:00
|
|
|
return;
|
2008-03-16 11:07:59 +01:00
|
|
|
|
2008-03-15 14:19:52 +01:00
|
|
|
switch(c->titlebar.position)
|
|
|
|
{
|
|
|
|
default:
|
2008-03-26 10:57:06 +01:00
|
|
|
return;
|
2008-04-04 10:26:46 +02:00
|
|
|
case Off:
|
|
|
|
return;
|
2008-03-15 14:19:52 +01:00
|
|
|
case Top:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
2008-03-24 17:42:45 +01:00
|
|
|
width = geometry.width + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-03-24 17:42:45 +01:00
|
|
|
width = MIN(c->titlebar.width, geometry.width);
|
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
x_offset = 2 * c->border + geometry.width - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-24 17:42:45 +01:00
|
|
|
geometry.x + x_offset,
|
2008-03-15 14:19:52 +01:00
|
|
|
geometry.y,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.height);
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
2008-03-24 17:42:45 +01:00
|
|
|
width = geometry.width + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-03-24 17:42:45 +01:00
|
|
|
width = MIN(c->titlebar.width, geometry.width);
|
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
x_offset = 2 * c->border + geometry.width - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-24 17:42:45 +01:00
|
|
|
geometry.x + x_offset,
|
2008-03-26 10:46:25 +01:00
|
|
|
geometry.y + geometry.height
|
2008-05-20 15:39:47 +02:00
|
|
|
- c->titlebar_sw->geometry.height + 2 * c->border,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.height);
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
2008-03-15 20:10:09 +01:00
|
|
|
case Left:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
2008-03-24 17:42:45 +01:00
|
|
|
width = geometry.height + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-03-24 17:42:45 +01:00
|
|
|
width = MIN(c->titlebar.width, geometry.height);
|
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
y_offset = 2 * c->border + geometry.height - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-15 20:10:09 +01:00
|
|
|
geometry.x,
|
2008-03-24 17:42:45 +01:00
|
|
|
geometry.y + y_offset,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.width,
|
2008-03-24 16:31:02 +01:00
|
|
|
width);
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-03-24 16:31:02 +01:00
|
|
|
if(!c->titlebar.width)
|
2008-03-24 17:42:45 +01:00
|
|
|
width = geometry.height + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-03-24 17:42:45 +01:00
|
|
|
width = MIN(c->titlebar.width, geometry.height);
|
|
|
|
switch(c->titlebar.align)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
|
|
|
y_offset = 2 * c->border + geometry.height - width;
|
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
simplewindow_move_resize(c->titlebar_sw,
|
2008-03-26 10:46:25 +01:00
|
|
|
geometry.x + geometry.width
|
2008-05-20 15:39:47 +02:00
|
|
|
- c->titlebar_sw->geometry.width + 2 * c->border,
|
2008-03-24 17:42:45 +01:00
|
|
|
geometry.y + y_offset,
|
2008-05-20 15:39:47 +02:00
|
|
|
c->titlebar_sw->geometry.width,
|
2008-03-24 16:31:02 +01:00
|
|
|
width);
|
2008-03-16 18:00:49 +01:00
|
|
|
break;
|
2008-03-15 14:19:52 +01:00
|
|
|
}
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/** Set client titlebar position.
|
|
|
|
* \param c The client.
|
|
|
|
* \param p The position.
|
|
|
|
*/
|
2008-04-24 22:58:25 +02:00
|
|
|
void
|
2008-05-20 15:39:47 +02:00
|
|
|
titlebar_init(client_t *c)
|
2008-04-24 22:58:25 +02:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
int width = 0, height = 0;
|
|
|
|
|
|
|
|
if(!c->titlebar.height)
|
|
|
|
c->titlebar.height = draw_text_extents(globalconf.connection, globalconf.default_screen,
|
|
|
|
globalconf.font,
|
|
|
|
client_markup_parse(c,
|
|
|
|
c->titlebar.text_focus,
|
|
|
|
a_strlen(c->titlebar.text_focus))).height;
|
|
|
|
switch(c->titlebar.position)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
c->titlebar.position = Off;
|
|
|
|
if(c->titlebar_sw)
|
|
|
|
xcb_unmap_window(globalconf.connection, c->titlebar_sw->window);
|
2008-04-24 22:58:25 +02:00
|
|
|
return;
|
2008-05-20 15:39:47 +02:00
|
|
|
return;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
if(!c->titlebar.width)
|
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
else
|
|
|
|
width = MIN(c->titlebar.width, c->geometry.width);
|
|
|
|
height = c->titlebar.height;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
if(!c->titlebar.width)
|
|
|
|
height = c->geometry.height + 2 * c->border;
|
|
|
|
else
|
|
|
|
height = MIN(c->titlebar.width, c->geometry.height);
|
|
|
|
width = c->titlebar.height;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-24 22:58:25 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* Delete old statusbar */
|
|
|
|
simplewindow_delete(&c->titlebar_sw);
|
|
|
|
|
|
|
|
c->titlebar_sw = simplewindow_new(globalconf.connection,
|
|
|
|
c->phys_screen, 0, 0,
|
|
|
|
width, height, 0);
|
|
|
|
titlebar_draw(c);
|
|
|
|
xcb_map_window(globalconf.connection, c->titlebar_sw->window);
|
2008-04-24 22:58:25 +02:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_titlebar_new(lua_State *L)
|
2008-03-15 13:59:04 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
titlebar_t **tb;
|
|
|
|
int objpos;
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
luaA_checktable(L, 1);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
tb = lua_newuserdata(L, sizeof(titlebar_t *));
|
|
|
|
*tb = p_new(titlebar_t, 1);
|
|
|
|
objpos = lua_gettop(L);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-05-23 16:39:35 +02:00
|
|
|
(*tb)->text_normal = a_strdup(luaA_getopt_string(L, 1, "text_normal", "<title/>"));
|
|
|
|
(*tb)->text_focus = a_strdup(luaA_getopt_string(L, 1, "text_focus", "<title/>"));
|
|
|
|
(*tb)->text_urgent = a_strdup(luaA_getopt_string(L, 1, "text_urgent", "<title/>"));
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
(*tb)->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
|
|
|
|
|
|
|
(*tb)->width = luaA_getopt_number(L, 1, "width", 0);
|
|
|
|
(*tb)->height = luaA_getopt_number(L, 1, "height", 0);
|
|
|
|
if((*tb)->height <= 0)
|
|
|
|
/* 1.5 as default factor, it fits nice but no one knows why */
|
|
|
|
(*tb)->height = 1.5 * globalconf.font->height;
|
|
|
|
|
|
|
|
(*tb)->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
|
|
|
|
|
|
|
titlebar_ref(tb);
|
|
|
|
|
|
|
|
lua_pushvalue(L, objpos);
|
|
|
|
return luaA_settype(L, "titlebar");
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_titlebar_mouse(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t i, len;
|
|
|
|
int b;
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *button;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
/* arg 1 is modkey table */
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
/* arg 2 is mouse button */
|
|
|
|
b = luaL_checknumber(L, 2);
|
|
|
|
/* arg 3 is cmd to run */
|
|
|
|
luaA_checkfunction(L, 3);
|
|
|
|
|
2008-05-23 13:35:46 +02:00
|
|
|
button = p_new(button_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
button->button = xutil_button_fromint(b);
|
|
|
|
button->fct = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
|
|
|
|
len = lua_objlen(L, 1);
|
|
|
|
for(i = 1; i <= len; i++)
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, 1, i);
|
|
|
|
button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
button_list_push(&globalconf.buttons.titlebar, button);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_titlebar_gc(lua_State *L)
|
|
|
|
{
|
|
|
|
titlebar_t **titlebar = luaL_checkudata(L, 1, "titlebar");
|
|
|
|
titlebar_unref(titlebar);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_titlebar_tostring(lua_State *L)
|
|
|
|
{
|
|
|
|
titlebar_t **p = luaL_checkudata(L, 1, "titlebar");
|
|
|
|
lua_pushfstring(L, "[titlebar udata(%p)]", *p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_titlebar_eq(lua_State *L)
|
|
|
|
{
|
|
|
|
titlebar_t **t1 = luaL_checkudata(L, 1, "titlebar");
|
|
|
|
titlebar_t **t2 = luaL_checkudata(L, 2, "titlebar");
|
|
|
|
lua_pushboolean(L, (*t1 == *t2));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct luaL_reg awesome_titlebar_methods[] =
|
|
|
|
{
|
|
|
|
{ "new", luaA_titlebar_new },
|
|
|
|
{ "mouse", luaA_titlebar_mouse },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_titlebar_meta[] =
|
|
|
|
{
|
|
|
|
{ "__eq", luaA_titlebar_eq },
|
|
|
|
{ "__gc", luaA_titlebar_gc },
|
|
|
|
{ "__tostring", luaA_titlebar_tostring },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2008-03-15 13:59:04 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|