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-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-04 11:50:21 +02:00
|
|
|
if(!c->titlebar || !c->titlebar->sw || !c->titlebar->position)
|
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-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-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-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
if(!c->titlebar || !c->titlebar->sw)
|
2008-03-15 16:41:59 +01:00
|
|
|
return;
|
|
|
|
|
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)
|
|
|
|
width = MIN(c->titlebar->width, c->geometry.width);
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = 2 * c->border + c->geometry.width - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = (c->geometry.width - width) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +02:00
|
|
|
simplewindow_move_resize(c->titlebar->sw,
|
|
|
|
c->geometry.x + x_offset,
|
|
|
|
c->geometry.y - c->titlebar->sw->geometry.height,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-06-04 11:50:21 +02:00
|
|
|
c->titlebar->sw->geometry.height);
|
2008-03-15 15:24:47 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = MIN(c->titlebar->width, c->geometry.width);
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = 2 * c->border + c->geometry.width - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = (c->geometry.width - width) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +02:00
|
|
|
simplewindow_move_resize(c->titlebar->sw,
|
|
|
|
c->geometry.x + x_offset,
|
|
|
|
c->geometry.y + c->geometry.height + 2 * c->border,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = MIN(c->titlebar->width, c->geometry.height);
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->geometry.height + 2 * c->border;
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = 2 * c->border + c->geometry.height - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = (c->geometry.height - width) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +02:00
|
|
|
simplewindow_move_resize(c->titlebar->sw,
|
|
|
|
c->geometry.x - c->titlebar->sw->geometry.width,
|
|
|
|
c->geometry.y + y_offset,
|
|
|
|
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-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = MIN(c->titlebar->width, c->geometry.height);
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->geometry.height + 2 * c->border;
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = 2 * c->border + c->geometry.height - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = (c->geometry.height - width) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +02:00
|
|
|
simplewindow_move_resize(c->titlebar->sw,
|
|
|
|
c->geometry.x + c->geometry.width + 2 * c->border,
|
|
|
|
c->geometry.y + y_offset,
|
|
|
|
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-06-04 11:50:21 +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.
|
2008-06-04 11:50:21 +02:00
|
|
|
* \param c The client.
|
|
|
|
* \param geometry The geometry the client will receive.
|
2008-04-04 10:26:46 +02:00
|
|
|
*/
|
2008-03-26 10:57:06 +01:00
|
|
|
void
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
if(!c->titlebar || !c->titlebar->sw)
|
2008-03-26 10:57:06 +01:00
|
|
|
return;
|
2008-03-16 11:07:59 +01:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
switch(c->titlebar->position)
|
2008-03-15 14:19:52 +01:00
|
|
|
{
|
|
|
|
default:
|
2008-03-26 10:57:06 +01:00
|
|
|
return;
|
2008-03-15 14:19:52 +01:00
|
|
|
case Top:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(!c->titlebar->width)
|
|
|
|
width = geometry.width + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = MIN(c->titlebar->width, geometry.width);
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
c->titlebar->sw->geometry.height);
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = geometry.width + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = MIN(c->titlebar->width, geometry.width);
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
x_offset = (geometry.width - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
- c->titlebar->sw->geometry.height + 2 * c->border,
|
2008-03-24 16:31:02 +01:00
|
|
|
width,
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
if(!c->titlebar->width)
|
|
|
|
width = geometry.height + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = MIN(c->titlebar->width, geometry.height);
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +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-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar->width)
|
|
|
|
width = geometry.height + 2 * c->border;
|
2008-03-24 16:31:02 +01:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = MIN(c->titlebar->width, geometry.height);
|
|
|
|
switch(c->titlebar->align)
|
2008-03-24 17:42:45 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case AlignRight:
|
2008-06-04 11:50:21 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-04 11:50:21 +02:00
|
|
|
simplewindow_move_resize(c->titlebar->sw,
|
2008-03-26 10:46:25 +01:00
|
|
|
geometry.x + geometry.width
|
2008-06-04 11:50:21 +02:00
|
|
|
- c->titlebar->sw->geometry.width + 2 * c->border,
|
2008-03-24 17:42:45 +01:00
|
|
|
geometry.y + y_offset,
|
2008-06-04 11:50:21 +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-06-04 11:50:21 +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.
|
|
|
|
*/
|
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-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)
|
|
|
|
width = MIN(c->titlebar->width, c->geometry.width);
|
2008-05-20 15:39:47 +02:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
width = c->geometry.width + 2 * c->border;
|
|
|
|
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)
|
|
|
|
height = MIN(c->titlebar->width, c->geometry.height);
|
2008-05-20 15:39:47 +02:00
|
|
|
else
|
2008-06-04 11:50:21 +02:00
|
|
|
height = c->geometry.height + 2 * c->border;
|
|
|
|
width = c->titlebar->height;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-04-24 22:58:25 +02:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
c->titlebar->sw = simplewindow_new(globalconf.connection,
|
2008-06-10 19:35:38 +02:00
|
|
|
c->phys_screen, 0, 0,
|
|
|
|
width, height, 0);
|
2008-06-04 11:50:21 +02:00
|
|
|
titlebar_draw(c);
|
|
|
|
xcb_map_window(globalconf.connection, c->titlebar->sw->window);
|
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
|
|
|
|
* \lparam A table with values: align, position, fg, bg, width and height.
|
|
|
|
* \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-03 18:41:54 +02:00
|
|
|
const char *color;
|
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-04 19:21:21 +02:00
|
|
|
tb->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
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-04 19:21:21 +02:00
|
|
|
tb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-03 18:41:54 +02:00
|
|
|
lua_getfield(L, 1, "fg");
|
|
|
|
if((color = luaL_optstring(L, -1, NULL)))
|
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-06-04 19:21:21 +02:00
|
|
|
color, &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
|
|
|
|
|
|
|
lua_getfield(L, 1, "bg");
|
|
|
|
if((color = luaL_optstring(L, -1, NULL)))
|
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-06-04 19:21:21 +02:00
|
|
|
color, &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-04 19:21:21 +02:00
|
|
|
return luaA_titlebar_userdata_new(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-03 18:41:54 +02:00
|
|
|
widget_node_t *w = p_new(widget_node_t, 1);
|
2008-06-04 13:27:13 +02:00
|
|
|
client_t *c;
|
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-03 18:41:54 +02:00
|
|
|
w->widget = *widget;
|
|
|
|
widget_node_list_append(&(*tb)->widgets, w);
|
|
|
|
widget_ref(widget);
|
|
|
|
|
2008-06-04 13:27:13 +02:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->titlebar == *tb)
|
|
|
|
{
|
|
|
|
titlebar_draw(c);
|
|
|
|
break;
|
|
|
|
}
|
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-04 13:29:45 +02:00
|
|
|
widget_node_t *widget;
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
for(widget = (*tb)->widgets; widget; widget = widget->next)
|
|
|
|
{
|
|
|
|
luaA_widget_userdata_new(widget->widget);
|
|
|
|
/* ref again for the list */
|
|
|
|
widget_ref(&widget->widget);
|
|
|
|
lua_rawseti(L, -2, i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)))
|
|
|
|
return luaA_client_userdata_new(c);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
lua_getfield(L, 2, "fg");
|
|
|
|
if((color = luaL_optstring(L, -1, NULL)))
|
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
|
|
|
color, &(*tb)->colors.fg);
|
|
|
|
|
|
|
|
lua_getfield(L, 2, "bg");
|
|
|
|
if((color = luaL_optstring(L, -1, NULL)))
|
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
|
|
|
color, &(*tb)->colors.bg);
|
|
|
|
|
|
|
|
titlebar_draw(client_getbytitlebar(*tb));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-04 13:36:13 +02:00
|
|
|
/** Create a new titlebar userdata.
|
|
|
|
* \param t The titlebar.
|
2008-06-15 15:33:37 +02:00
|
|
|
* \return The number of value pushed.
|
2008-06-04 13:36:13 +02:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_titlebar_userdata_new(titlebar_t *t)
|
|
|
|
{
|
|
|
|
titlebar_t **tb = lua_newuserdata(globalconf.L, sizeof(titlebar_t *));
|
|
|
|
*tb = t;
|
|
|
|
titlebar_ref(tb);
|
|
|
|
return luaA_settype(globalconf.L, "titlebar");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-16 11:31:38 +02:00
|
|
|
DO_LUA_GC(titlebar_t, titlebar, "titlebar", titlebar_unref)
|
2008-06-16 11:37:55 +02:00
|
|
|
DO_LUA_EQ(titlebar_t, titlebar, "titlebar")
|
2008-06-16 11:31:38 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
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-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
|