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-06-03 18:41:54 +02:00
|
|
|
#include "widget.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-06-18 18:31:35 +02:00
|
|
|
DO_LUA_NEW(extern, titlebar_t, titlebar, "titlebar", titlebar_ref)
|
|
|
|
DO_LUA_GC(titlebar_t, titlebar, "titlebar", titlebar_unref)
|
|
|
|
DO_LUA_EQ(titlebar_t, titlebar, "titlebar")
|
|
|
|
|
2008-06-04 17:54:52 +02:00
|
|
|
/** Get a client by its titlebar.
|
|
|
|
* \param titlebar The titlebar.
|
|
|
|
* \return A client.
|
|
|
|
*/
|
|
|
|
client_t *
|
|
|
|
client_getbytitlebar(titlebar_t *titlebar)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->titlebar == titlebar)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
/** Get a client by its titlebar window.
|
2008-06-04 17:54:52 +02:00
|
|
|
* \param win The window.
|
2008-06-04 11:50:21 +02:00
|
|
|
* \return A client.
|
2008-06-03 18:41:54 +02:00
|
|
|
*/
|
2008-06-04 11:50:21 +02:00
|
|
|
client_t *
|
|
|
|
client_getbytitlebarwin(xcb_window_t win)
|
2008-04-23 17:44:09 +02:00
|
|
|
{
|
2008-06-04 11:50:21 +02:00
|
|
|
client_t *c;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->titlebar && c->titlebar->sw && c->titlebar->sw->window == win)
|
|
|
|
return c;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
|
|
|
return NULL;
|
2008-03-25 14:45:13 +01:00
|
|
|
}
|
|
|
|
|
2008-04-04 10:26:46 +02:00
|
|
|
/** Draw the titlebar content.
|
2008-06-04 11:50:21 +02:00
|
|
|
* \param c The client.
|
2008-04-04 10:26:46 +02:00
|
|
|
*/
|
2008-03-15 13:59:04 +01:00
|
|
|
void
|
2008-06-04 11:50:21 +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-21 16:50:17 +01:00
|
|
|
xcb_screen_t *s;
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-18 18:32:09 +02:00
|
|
|
if(!c || !c->titlebar || !c->titlebar->sw || !c->titlebar->position)
|
2008-03-15 20:10:09 +01:00
|
|
|
return;
|
|
|
|
|
2008-06-17 16:55:24 +02:00
|
|
|
s = xutil_screen_get(globalconf.connection,
|
2008-06-04 11:50:21 +02:00
|
|
|
c->titlebar->sw->phys_screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->position)
|
2008-03-15 20:10:09 +01:00
|
|
|
{
|
|
|
|
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-06-04 11:50:21 +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-06-02 12:18:17 +02:00
|
|
|
dw,
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
&c->titlebar->colors.fg,
|
|
|
|
&c->titlebar->colors.bg);
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-06-04 11:50:21 +02:00
|
|
|
ctx = draw_context_new(globalconf.connection, c->titlebar->sw->phys_screen,
|
|
|
|
c->titlebar->sw->geometry.width,
|
|
|
|
c->titlebar->sw->geometry.height,
|
2008-06-04 16:13:41 +02:00
|
|
|
c->titlebar->sw->pixmap,
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
&c->titlebar->colors.fg,
|
|
|
|
&c->titlebar->colors.bg);
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-04 16:13:41 +02:00
|
|
|
widget_render(c->titlebar->widgets, ctx, c->titlebar->sw->gc, c->titlebar->sw->pixmap,
|
2008-06-09 21:43:09 +02:00
|
|
|
c->screen, c->titlebar->position,
|
2008-07-29 16:51:21 +02:00
|
|
|
c->titlebar->sw->geometry.x, c->titlebar->sw->geometry.y,
|
|
|
|
c->titlebar, AWESOME_TYPE_TITLEBAR);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->position)
|
2008-03-15 20:10:09 +01:00
|
|
|
{
|
|
|
|
case Left:
|
2008-06-04 16:13:41 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
|
2008-05-30 17:53:10 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
2008-06-04 11:50:21 +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-06-04 16:13:41 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
|
2008-05-30 17:53:10 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
2008-06-04 11:50:21 +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-06-04 16:13:41 +02:00
|
|
|
simplewindow_refresh_pixmap(c->titlebar->sw);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-03-21 11:26:56 +01:00
|
|
|
draw_context_delete(&ctx);
|
2008-07-31 14:10:54 +02:00
|
|
|
|
|
|
|
c->titlebar->need_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Titlebar refresh function.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_refresh(void)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->titlebar && c->titlebar->need_update)
|
|
|
|
titlebar_draw(c);
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-03-15 15:24:47 +01:00
|
|
|
void
|
2008-06-18 11:22:54 +02:00
|
|
|
titlebar_geometry_compute(client_t *c, area_t geometry, area_t *res)
|
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-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->position)
|
2008-03-15 15:24:47 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case Top:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->border.width));
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->border.width);
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-18 11:22:54 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->border.width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-18 11:22:54 +02:00
|
|
|
res->x = geometry.x + x_offset;
|
2008-06-18 17:05:10 +02:00
|
|
|
res->y = geometry.y - c->titlebar->height - 2 * c->titlebar->border.width + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->width = width;
|
|
|
|
res->height = c->titlebar->height;
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, MIN(c->titlebar->width, geometry.width - 2 * c->titlebar->border.width));
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->border.width);
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-18 11:22:54 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->border.width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-18 11:22:54 +02:00
|
|
|
res->x = geometry.x + x_offset;
|
2008-06-18 17:05:10 +02:00
|
|
|
res->y = geometry.y + geometry.height + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->width = width;
|
|
|
|
res->height = c->titlebar->height;
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
2008-03-15 20:10:09 +01:00
|
|
|
case Left:
|
2008-06-18 11:22:54 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->border.width));
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->border.width);
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-18 11:22:54 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->border.width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-18 17:05:10 +02:00
|
|
|
res->x = geometry.x - c->titlebar->height + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->y = geometry.y + y_offset;
|
|
|
|
res->width = c->titlebar->height;
|
|
|
|
res->height = width;
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, MIN(c->titlebar->width, geometry.height - 2 * c->titlebar->border.width));
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->border.width);
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-18 11:22:54 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->border.width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-18 17:05:10 +02:00
|
|
|
res->x = geometry.x + geometry.width + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->y = geometry.y + y_offset;
|
|
|
|
res->width = c->titlebar->height;
|
|
|
|
res->height = 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-05-20 15:39:47 +02:00
|
|
|
/** Set client titlebar position.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
2008-04-24 22:58:25 +02:00
|
|
|
void
|
2008-06-04 11:50:21 +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;
|
2008-06-18 11:22:54 +02:00
|
|
|
area_t geom;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->position)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
default:
|
2008-06-04 11:50:21 +02:00
|
|
|
c->titlebar->position = Off;
|
2008-05-20 15:39:47 +02:00
|
|
|
return;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
2008-06-18 11:22:54 +02:00
|
|
|
width = MIN(c->titlebar->width, c->geometry.width - 2 * c->titlebar->border.width);
|
2008-05-20 15:39:47 +02:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
width = c->geometry.width + 2 * c->border - 2 * c->titlebar->border.width;
|
2008-06-04 11:50:21 +02:00
|
|
|
height = c->titlebar->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
2008-06-18 11:22:54 +02:00
|
|
|
height = MIN(c->titlebar->width, c->geometry.height - 2 * c->titlebar->border.width);
|
2008-05-20 15:39:47 +02:00
|
|
|
else
|
2008-06-18 11:22:54 +02:00
|
|
|
height = c->geometry.height + 2 * c->border - 2 * c->titlebar->border.width;
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->titlebar->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-06-23 20:37:31 +02:00
|
|
|
|
2008-06-18 11:22:54 +02:00
|
|
|
titlebar_geometry_compute(c, c->geometry, &geom);
|
|
|
|
|
|
|
|
c->titlebar->sw = simplewindow_new(globalconf.connection, c->phys_screen, geom.x, geom.y,
|
|
|
|
geom.width, geom.height, c->titlebar->border.width);
|
2008-06-18 11:58:40 +02:00
|
|
|
|
2008-06-18 11:22:54 +02:00
|
|
|
if(c->titlebar->border.width)
|
|
|
|
xcb_change_window_attributes(globalconf.connection, c->titlebar->sw->window,
|
|
|
|
XCB_CW_BORDER_PIXEL, &c->titlebar->border.color.pixel);
|
2008-04-24 22:58:25 +02:00
|
|
|
|
2008-06-18 11:22:54 +02:00
|
|
|
if(client_isvisible(c, c->screen))
|
2008-06-18 11:58:40 +02:00
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
|
2008-07-31 14:10:54 +02:00
|
|
|
c->titlebar->need_update = true;
|
2008-04-24 22:58:25 +02:00
|
|
|
}
|
|
|
|
|
2008-06-03 18:41:54 +02:00
|
|
|
/** Create a new titlebar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-06-15 15:33:37 +02:00
|
|
|
* \return The number of value pushed.
|
2008-06-10 20:12:51 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-18 11:27:51 +02:00
|
|
|
* \lparam A table with values: align, position, fg, bg, border_width,
|
|
|
|
* border_color, width and height.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A brand new titlebar.
|
2008-06-03 18:41:54 +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-06-04 19:21:21 +02:00
|
|
|
titlebar_t *tb;
|
2008-06-23 20:37:31 +02:00
|
|
|
const char *buf;
|
2008-06-23 14:01:33 +02:00
|
|
|
size_t len;
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
luaA_checktable(L, 2);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-04 19:21:21 +02:00
|
|
|
tb = p_new(titlebar_t, 1);
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
|
2008-06-24 22:24:13 +02:00
|
|
|
tb->align = draw_align_fromstr(buf, len);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
tb->width = luaA_getopt_number(L, 2, "width", 0);
|
|
|
|
tb->height = luaA_getopt_number(L, 2, "height", 0);
|
2008-06-04 19:21:21 +02:00
|
|
|
if(tb->height <= 0)
|
2008-05-20 15:39:47 +02:00
|
|
|
/* 1.5 as default factor, it fits nice but no one knows why */
|
2008-06-04 19:21:21 +02:00
|
|
|
tb->height = 1.5 * globalconf.font->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "position", "top", &len);
|
2008-06-23 20:37:31 +02:00
|
|
|
tb->position = position_fromstr(buf, len);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-07-24 18:18:18 +02:00
|
|
|
tb->colors.fg = globalconf.colors.fg;
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
|
2008-07-24 18:18:18 +02:00
|
|
|
xcolor_init(&tb->colors.fg, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len);
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-07-24 18:18:18 +02:00
|
|
|
tb->colors.bg = globalconf.colors.bg;
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
|
2008-07-24 18:18:18 +02:00
|
|
|
xcolor_init(&tb->colors.bg, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len);
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-07-24 18:18:18 +02:00
|
|
|
tb->border.color = globalconf.colors.fg;
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len)))
|
2008-07-24 18:18:18 +02:00
|
|
|
xcolor_init(&tb->border.color, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len);
|
2008-06-18 11:22:54 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
tb->border.width = luaA_getopt_number(L, 2, "border_width", 0);
|
2008-06-18 11:22:54 +02:00
|
|
|
|
2008-06-18 18:31:35 +02:00
|
|
|
return luaA_titlebar_userdata_new(globalconf.L, tb);
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 18:19:33 +02:00
|
|
|
/** Titlebar newindex.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
|
|
|
|
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
2008-08-08 16:02:35 +02:00
|
|
|
client_t *c = NULL, **newc;
|
2008-07-01 18:28:17 +02:00
|
|
|
int i;
|
2008-08-08 16:49:26 +02:00
|
|
|
widget_node_t *witer;
|
2008-08-08 17:15:23 +02:00
|
|
|
position_t position;
|
2008-07-01 18:19:33 +02:00
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-08-08 16:02:35 +02:00
|
|
|
case A_TK_CLIENT:
|
|
|
|
if(!lua_isnil(L, 3))
|
|
|
|
newc = luaA_checkudata(L, 3, "client");
|
|
|
|
else
|
|
|
|
newc = NULL;
|
|
|
|
|
|
|
|
if(newc)
|
|
|
|
{
|
|
|
|
if((*newc)->titlebar)
|
|
|
|
{
|
|
|
|
simplewindow_delete(&(*newc)->titlebar->sw);
|
|
|
|
titlebar_unref(&(*newc)->titlebar);
|
|
|
|
globalconf.screens[(*newc)->screen].need_arrange = true;
|
|
|
|
}
|
|
|
|
/* Attach titlebar to client */
|
|
|
|
(*newc)->titlebar = *titlebar;
|
|
|
|
titlebar_ref(titlebar);
|
|
|
|
titlebar_init(*newc);
|
|
|
|
c = *newc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if((c = client_getbytitlebar(*titlebar)))
|
|
|
|
{
|
|
|
|
simplewindow_delete(&(*titlebar)->sw);
|
|
|
|
/* unref and NULL the ref */
|
|
|
|
titlebar_unref(&c->titlebar);
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-07-01 18:19:33 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
|
|
|
(*titlebar)->align = draw_align_fromstr(buf, len);
|
2008-07-01 18:28:17 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2008-07-01 18:19:33 +02:00
|
|
|
break;
|
2008-07-01 18:28:17 +02:00
|
|
|
case A_TK_BORDER_WIDTH:
|
|
|
|
if((i = luaL_checknumber(L, 3)) >= 0)
|
|
|
|
(*titlebar)->border.width = i;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_COLOR:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
|
|
|
if(xcolor_init(&(*titlebar)->border.color, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len))
|
|
|
|
if((*titlebar)->sw)
|
|
|
|
xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window,
|
|
|
|
XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel);
|
2008-07-01 18:28:17 +02:00
|
|
|
return 0;
|
2008-07-01 18:33:09 +02:00
|
|
|
case A_TK_FG:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
|
|
|
if(xcolor_init(&(*titlebar)->colors.fg, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len))
|
2008-07-31 14:10:54 +02:00
|
|
|
(*titlebar)->need_update = true;
|
2008-07-01 18:33:09 +02:00
|
|
|
return 0;
|
|
|
|
case A_TK_BG:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
|
|
|
if(xcolor_init(&(*titlebar)->colors.bg, globalconf.connection,
|
|
|
|
globalconf.default_screen, buf, len))
|
2008-07-31 14:10:54 +02:00
|
|
|
(*titlebar)->need_update = true;
|
2008-07-01 18:33:09 +02:00
|
|
|
return 0;
|
2008-08-08 16:49:26 +02:00
|
|
|
case A_TK_WIDGETS:
|
|
|
|
luaA_checktable(L, 3);
|
|
|
|
|
|
|
|
/* remove all widgets */
|
|
|
|
for(witer = (*titlebar)->widgets; witer; witer = (*titlebar)->widgets)
|
|
|
|
{
|
|
|
|
if(witer->widget->detach)
|
|
|
|
witer->widget->detach(witer->widget, *titlebar);
|
|
|
|
widget_unref(&witer->widget);
|
|
|
|
widget_node_list_detach(&(*titlebar)->widgets, witer);
|
|
|
|
p_delete(&witer);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*titlebar)->need_update = true;
|
|
|
|
|
|
|
|
/* now read all widgets and add them */
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 3))
|
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, -1, "widget");
|
|
|
|
widget_node_t *w = p_new(widget_node_t, 1);
|
|
|
|
w->widget = *widget;
|
|
|
|
widget_node_list_append(&(*titlebar)->widgets, w);
|
|
|
|
widget_ref(widget);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
break;
|
2008-08-08 17:15:23 +02:00
|
|
|
case A_TK_POSITION:
|
|
|
|
buf = luaL_checklstring(L, 3, &len);
|
|
|
|
position = position_fromstr(buf, len);
|
|
|
|
if(position != (*titlebar)->position)
|
|
|
|
{
|
|
|
|
(*titlebar)->position = position;
|
|
|
|
c = client_getbytitlebar(*titlebar);
|
|
|
|
simplewindow_delete(&c->titlebar->sw);
|
|
|
|
titlebar_init(c);
|
|
|
|
}
|
|
|
|
break;
|
2008-07-01 18:19:33 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-08 16:02:35 +02:00
|
|
|
if((c || (c = client_getbytitlebar(*titlebar)))
|
2008-07-01 18:28:17 +02:00
|
|
|
&& client_isvisible(c, c->screen))
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
|
2008-07-01 18:19:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Titlebar object.
|
2008-07-01 18:19:33 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \luastack
|
2008-08-08 16:02:35 +02:00
|
|
|
* \lfield client The client attached to this titlebar.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \lfield align Alignment relative to the client.
|
|
|
|
* \lfield border_width Border width.
|
|
|
|
* \lfield border_color Border color.
|
|
|
|
* \lfield fg Foreground color.
|
|
|
|
* \lfield bg Background color.
|
2008-08-08 17:10:29 +02:00
|
|
|
* \lfield position Position.
|
2008-07-01 18:19:33 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_index(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
|
|
|
|
const char *attr = luaL_checklstring(L, 2, &len);
|
2008-08-08 16:02:35 +02:00
|
|
|
client_t *c;
|
2008-08-08 16:49:26 +02:00
|
|
|
widget_node_t *witer;
|
|
|
|
int i = 0;
|
2008-07-01 18:19:33 +02:00
|
|
|
|
2008-07-01 19:25:58 +02:00
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
2008-07-01 18:19:33 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch(a_tokenize(attr, len))
|
|
|
|
{
|
2008-08-08 16:02:35 +02:00
|
|
|
case A_TK_CLIENT:
|
|
|
|
if((c = client_getbytitlebar(*titlebar)))
|
|
|
|
return luaA_client_userdata_new(L, c);
|
|
|
|
else
|
|
|
|
return 0;
|
2008-07-01 18:19:33 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
lua_pushstring(L, draw_align_tostr((*titlebar)->align));
|
|
|
|
break;
|
2008-07-01 18:28:17 +02:00
|
|
|
case A_TK_BORDER_WIDTH:
|
|
|
|
lua_pushnumber(L, (*titlebar)->border.width);
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_COLOR:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*titlebar)->border.color);
|
2008-07-01 18:28:17 +02:00
|
|
|
break;
|
2008-07-01 18:33:09 +02:00
|
|
|
case A_TK_FG:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*titlebar)->colors.fg);
|
2008-07-01 18:33:09 +02:00
|
|
|
break;
|
|
|
|
case A_TK_BG:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*titlebar)->colors.bg);
|
2008-07-01 18:33:09 +02:00
|
|
|
break;
|
2008-08-08 16:49:26 +02:00
|
|
|
case A_TK_WIDGETS:
|
|
|
|
lua_newtable(L);
|
|
|
|
for(witer = (*titlebar)->widgets; witer; witer = witer->next)
|
|
|
|
{
|
|
|
|
luaA_widget_userdata_new(L, witer->widget);
|
|
|
|
lua_rawseti(L, -2, ++i);
|
|
|
|
}
|
|
|
|
break;
|
2008-08-08 17:10:29 +02:00
|
|
|
case A_TK_POSITION:
|
|
|
|
lua_pushstring(L, position_tostr((*titlebar)->position));
|
|
|
|
break;
|
2008-07-01 18:19:33 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-15 15:33:37 +02:00
|
|
|
/** Convert a titlebar to a printable string.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of value pushed.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A titlebar.
|
|
|
|
* \lreturn A string.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_titlebar_tostring(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
titlebar_t **p = luaA_checkudata(L, 1, "titlebar");
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_pushfstring(L, "[titlebar udata(%p)]", *p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct luaL_reg awesome_titlebar_methods[] =
|
|
|
|
{
|
2008-06-30 14:01:55 +02:00
|
|
|
{ "__call", luaA_titlebar_new },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_titlebar_meta[] =
|
|
|
|
{
|
2008-07-01 18:19:33 +02:00
|
|
|
{ "__index", luaA_titlebar_index },
|
|
|
|
{ "__newindex", luaA_titlebar_newindex },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "__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
|