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-06-03 18:41:54 +02:00
|
|
|
#include "widget.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-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,
|
2008-06-04 11:50:21 +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,
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
c->titlebar->sw->geometry.x, c->titlebar->sw->geometry.y, c->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-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;
|
|
|
|
|
|
|
|
titlebar_draw(c);
|
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-05-20 15:39:47 +02:00
|
|
|
luaA_checktable(L, 1);
|
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-25 17:33:05 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 1, "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-04 19:21:21 +02:00
|
|
|
tb->width = luaA_getopt_number(L, 1, "width", 0);
|
|
|
|
tb->height = luaA_getopt_number(L, 1, "height", 0);
|
|
|
|
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-25 17:33:05 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 1, "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-06-25 17:33:05 +02:00
|
|
|
if((buf = luaA_getopt_string(L, -1, "fg", NULL)))
|
2008-06-03 18:41:54 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-06-23 20:37:31 +02:00
|
|
|
buf, &tb->colors.fg);
|
2008-06-03 18:41:54 +02:00
|
|
|
else
|
2008-06-04 19:21:21 +02:00
|
|
|
tb->colors.fg = globalconf.colors.fg;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-06-25 17:33:05 +02:00
|
|
|
if((buf = luaA_getopt_string(L, 1, "bg", NULL)))
|
2008-06-03 18:41:54 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-06-23 20:37:31 +02:00
|
|
|
buf, &tb->colors.bg);
|
2008-06-03 18:41:54 +02:00
|
|
|
else
|
2008-06-04 19:21:21 +02:00
|
|
|
tb->colors.bg = globalconf.colors.bg;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-06-25 17:33:05 +02:00
|
|
|
if((buf = luaA_getopt_string(L, 1, "border_color", NULL)))
|
2008-06-18 11:22:54 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-06-23 20:37:31 +02:00
|
|
|
buf, &tb->border.color);
|
2008-06-18 11:22:54 +02:00
|
|
|
|
|
|
|
tb->border.width = luaA_getopt_number(L, 1, "border_width", 0);
|
|
|
|
|
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-06-03 18:41:54 +02:00
|
|
|
/** Add a widget to a 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-11 02:46:30 +02:00
|
|
|
* \lvalue A titlebar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lparam A widget.
|
2008-06-03 18:41:54 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_widget_add(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
|
|
|
|
widget_t **widget = luaA_checkudata(L, 2, "widget");
|
2008-06-18 16:37:26 +02:00
|
|
|
widget_node_t *witer, *w = p_new(widget_node_t, 1);
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
if((*widget)->type == systray_new)
|
|
|
|
luaL_error(L, "cannot add systray widget to titlebar");
|
|
|
|
|
2008-06-18 16:37:26 +02:00
|
|
|
/* check that there is not already a widget with that name in the titlebar */
|
|
|
|
for(witer = (*tb)->widgets; witer; witer = witer->next)
|
2008-06-18 18:38:08 +02:00
|
|
|
if(witer->widget != *widget
|
|
|
|
&& !a_strcmp(witer->widget->name, (*widget)->name))
|
2008-06-18 16:37:26 +02:00
|
|
|
luaL_error(L, "a widget with name `%s' already on titlebar", witer->widget->name);
|
|
|
|
|
2008-06-03 18:41:54 +02:00
|
|
|
w->widget = *widget;
|
|
|
|
widget_node_list_append(&(*tb)->widgets, w);
|
|
|
|
widget_ref(widget);
|
|
|
|
|
2008-06-18 17:15:03 +02:00
|
|
|
titlebar_draw(client_getbytitlebar(*tb));
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-04 13:29:45 +02:00
|
|
|
/** Get all widgets from a 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-11 02:46:30 +02:00
|
|
|
* \lvalue A titlebar
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A table with all widgets from the titlebar.
|
2008-06-04 13:29:45 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_widget_get(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
|
2008-06-18 16:37:26 +02:00
|
|
|
widget_node_t *witer;
|
2008-06-04 13:29:45 +02:00
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
2008-06-18 16:37:26 +02:00
|
|
|
for(witer = (*tb)->widgets; witer; witer = witer->next)
|
2008-06-04 13:29:45 +02:00
|
|
|
{
|
2008-06-18 18:31:35 +02:00
|
|
|
luaA_widget_userdata_new(L, witer->widget);
|
2008-06-18 16:37:26 +02:00
|
|
|
lua_setfield(L, -2, witer->widget->name);
|
2008-06-04 13:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-04 17:54:52 +02:00
|
|
|
/** Get the client which the titlebar is attached to. That is a the same as
|
|
|
|
* checking if every clients's titlebar is equal to titlebar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A titlebar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A client if the titlebar is attached, nil otherwise.
|
2008-06-04 17:54:52 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_client_get(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
|
2008-06-04 17:54:52 +02:00
|
|
|
client_t *c;
|
|
|
|
|
|
|
|
if((c = client_getbytitlebar(*titlebar)))
|
2008-06-18 18:31:35 +02:00
|
|
|
return luaA_client_userdata_new(L, c);
|
2008-06-04 17:54:52 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-15 15:33:37 +02:00
|
|
|
/** Set titlebar colors.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of value pushed.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A titlebar.
|
|
|
|
* \lparam A table with keys `fg' and `bg', for foreground and background colors.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_colors_set(lua_State *L)
|
|
|
|
{
|
|
|
|
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
|
|
|
|
const char *color;
|
|
|
|
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
|
2008-06-25 17:33:05 +02:00
|
|
|
if((color = luaA_getopt_string(L, 2, "fg", NULL)))
|
2008-06-15 15:33:37 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
|
|
|
color, &(*tb)->colors.fg);
|
|
|
|
|
2008-06-25 17:33:05 +02:00
|
|
|
if((color = luaA_getopt_string(L, 2, "bg", NULL)))
|
2008-06-15 15:33:37 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
|
|
|
color, &(*tb)->colors.bg);
|
|
|
|
|
|
|
|
titlebar_draw(client_getbytitlebar(*tb));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-18 11:58:40 +02:00
|
|
|
/** Set titlebar border color and width.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of value pushed.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A titlebar.
|
|
|
|
* \lparam A table with keys `color' and `width'.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_titlebar_border_set(lua_State *L)
|
|
|
|
{
|
|
|
|
titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
|
|
|
|
client_t *c;
|
|
|
|
const char *color;
|
|
|
|
int border_width;
|
|
|
|
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
|
2008-06-25 17:33:05 +02:00
|
|
|
if((color = luaA_getopt_string(L, 2, "color", NULL)))
|
2008-06-18 11:58:40 +02:00
|
|
|
{
|
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
|
|
|
color, &(*tb)->border.color);
|
|
|
|
if((*tb)->sw)
|
|
|
|
xcb_change_window_attributes(globalconf.connection, (*tb)->sw->window,
|
|
|
|
XCB_CW_BORDER_PIXEL, &(*tb)->border.color.pixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((border_width = luaA_getopt_number(L, 2, "width", -1)) >= 0)
|
|
|
|
{
|
|
|
|
(*tb)->border.width = border_width;
|
|
|
|
if((*tb)->sw)
|
|
|
|
simplewindow_border_width_set((*tb)->sw, border_width);
|
|
|
|
if((c = client_getbytitlebar(*tb)) && client_isvisible(c, c->screen))
|
|
|
|
{
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
if(c->isfloating)
|
|
|
|
titlebar_update_geometry_floating(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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[] =
|
|
|
|
{
|
|
|
|
{ "new", luaA_titlebar_new },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_titlebar_meta[] =
|
|
|
|
{
|
2008-06-03 18:41:54 +02:00
|
|
|
{ "widget_add", luaA_titlebar_widget_add },
|
2008-06-04 13:29:45 +02:00
|
|
|
{ "widget_get", luaA_titlebar_widget_get },
|
2008-06-04 17:54:52 +02:00
|
|
|
{ "client_get", luaA_titlebar_client_get },
|
2008-06-15 15:33:37 +02:00
|
|
|
{ "colors_set", luaA_titlebar_colors_set },
|
2008-06-18 11:58:40 +02:00
|
|
|
{ "border_set", luaA_titlebar_border_set },
|
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
|