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>
|
|
|
|
|
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-09-21 10:13:21 +02:00
|
|
|
#include "wibox.h"
|
2008-09-24 12:13:21 +02:00
|
|
|
#include "screen.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 *
|
2008-09-21 10:13:21 +02:00
|
|
|
client_getbytitlebar(wibox_t *titlebar)
|
2008-06-04 17:54:52 +02:00
|
|
|
{
|
|
|
|
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)
|
2008-09-20 21:24:16 +02:00
|
|
|
if(c->titlebar && c->titlebar->sw.window == win)
|
2008-06-04 11:50:21 +02:00
|
|
|
return c;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
|
|
|
return NULL;
|
2008-03-25 14:45:13 +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-09-24 12:13:21 +02:00
|
|
|
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->sw.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-09-20 21:24:16 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->sw.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-09-24 12:13:21 +02:00
|
|
|
res->y = geometry.y - c->titlebar->sw.geometry.height - 2 * c->titlebar->sw.border.width + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->width = width;
|
2008-09-24 12:13:21 +02:00
|
|
|
res->height = c->titlebar->sw.geometry.height;
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-09-24 12:13:21 +02:00
|
|
|
width = MAX(1, geometry.width + 2 * c->border - 2 * c->titlebar->sw.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-09-20 21:24:16 +02:00
|
|
|
x_offset = 2 * c->border + geometry.width - width - 2 * c->titlebar->sw.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;
|
2008-09-24 12:13:21 +02:00
|
|
|
res->height = 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-09-24 12:13:21 +02:00
|
|
|
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->sw.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-09-20 21:24:16 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->sw.border.width;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
|
|
|
y_offset = (geometry.height - width) / 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-24 12:13:21 +02:00
|
|
|
res->x = geometry.x - c->titlebar->sw.geometry.width + c->border;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->y = geometry.y + y_offset;
|
2008-09-24 12:13:21 +02:00
|
|
|
res->width = c->titlebar->sw.geometry.width;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->height = width;
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-09-24 12:13:21 +02:00
|
|
|
width = MAX(1, geometry.height + 2 * c->border - 2 * c->titlebar->sw.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-09-20 21:24:16 +02:00
|
|
|
y_offset = 2 * c->border + geometry.height - width - 2 * c->titlebar->sw.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;
|
2008-09-24 12:13:21 +02:00
|
|
|
res->width = c->titlebar->sw.geometry.width;
|
2008-06-18 11:22:54 +02:00
|
|
|
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-09-21 20:39:23 +02:00
|
|
|
/** Create a new titlebar (DEPRECATED).
|
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-09-21 20:39:23 +02:00
|
|
|
deprecate();
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
return luaA_wibox_new(L);
|
|
|
|
}
|
2008-06-18 11:22:54 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/** Detach a wibox titlebar from its client.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_client_detach(client_t *c)
|
|
|
|
{
|
|
|
|
/* If client has a titlebar, kick it out. */
|
|
|
|
if(c && c->titlebar)
|
|
|
|
{
|
|
|
|
wibox_unref(&c->titlebar);
|
|
|
|
simplewindow_wipe(&c->titlebar->sw);
|
2008-09-24 12:13:21 +02:00
|
|
|
c->titlebar->type = WIBOX_TYPE_NORMAL;
|
|
|
|
c->titlebar->screen = SCREEN_UNDEF;
|
2008-09-21 20:39:23 +02:00
|
|
|
c->titlebar = NULL;
|
|
|
|
client_need_arrange(c);
|
|
|
|
client_stack();
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 11:22:54 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/** Attach a wibox to a client as its titlebar.
|
|
|
|
* \param c The client.
|
|
|
|
* \param t The wibox/titlebar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_client_attach(client_t *c, wibox_t *t)
|
|
|
|
{
|
|
|
|
titlebar_client_detach(c);
|
2008-08-12 14:53:57 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
if(c && t)
|
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
area_t wingeom;
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
/* check if titlebar is already on a client */
|
|
|
|
titlebar_client_detach(client_getbytitlebar(t));
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
c->titlebar = wibox_ref(&t);
|
|
|
|
t->type = WIBOX_TYPE_TITLEBAR;
|
2008-09-24 12:13:21 +02:00
|
|
|
t->screen = c->screen;
|
|
|
|
|
|
|
|
switch(t->position)
|
|
|
|
{
|
|
|
|
case Floating:
|
|
|
|
t->position = Top;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
if(!t->sw.geometry.height)
|
|
|
|
t->sw.geometry.height = 1.5 * globalconf.font->height;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
if(!t->sw.geometry.width)
|
|
|
|
t->sw.geometry.width = 1.5 * globalconf.font->height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
titlebar_geometry_compute(c, c->geometry, &wingeom);
|
|
|
|
|
|
|
|
simplewindow_init(&t->sw, c->phys_screen,
|
|
|
|
wingeom, 0, t->sw.orientation,
|
|
|
|
&t->sw.ctx.fg, &t->sw.ctx.bg);
|
|
|
|
simplewindow_border_color_set(&t->sw, &t->sw.border.color);
|
|
|
|
|
|
|
|
t->need_update = true;
|
|
|
|
|
|
|
|
if(t->isvisible)
|
|
|
|
xcb_map_window(globalconf.connection, t->sw.window);
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
client_need_arrange(c);
|
|
|
|
client_stack();
|
|
|
|
}
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 18:19:33 +02:00
|
|
|
/** Titlebar newindex.
|
|
|
|
* \param L The Lua VM state.
|
2008-09-21 20:39:23 +02:00
|
|
|
* \param titlebar The wibox titlebar.
|
|
|
|
* \param tok The attribute token.
|
2008-07-01 18:19:33 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
2008-09-21 20:39:23 +02:00
|
|
|
int
|
|
|
|
luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok)
|
2008-07-01 18:19:33 +02:00
|
|
|
{
|
2008-09-20 21:24:16 +02:00
|
|
|
client_t *c = NULL;
|
2008-07-01 18:19:33 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
switch(tok)
|
2008-07-01 18:19:33 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
position_t position;
|
|
|
|
int i;
|
|
|
|
size_t len;
|
|
|
|
const char *buf;
|
|
|
|
|
2008-07-01 18:19:33 +02:00
|
|
|
case A_TK_ALIGN:
|
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
2008-09-21 20:39:23 +02:00
|
|
|
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)
|
2008-09-24 12:13:21 +02:00
|
|
|
simplewindow_border_width_set(&titlebar->sw, i);
|
2008-07-01 18:28:17 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_COLOR:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
2008-09-24 12:13:21 +02:00
|
|
|
if(xcolor_init_reply(xcolor_init_unchecked(&titlebar->sw.border.color, buf, len)))
|
|
|
|
simplewindow_border_color_set(&c->titlebar->sw, &c->titlebar->sw.border.color);
|
2008-07-01 18:28:17 +02:00
|
|
|
return 0;
|
2008-08-08 17:15:23 +02:00
|
|
|
case A_TK_POSITION:
|
|
|
|
buf = luaL_checklstring(L, 3, &len);
|
|
|
|
position = position_fromstr(buf, len);
|
2008-09-21 20:39:23 +02:00
|
|
|
if(position != titlebar->position)
|
2008-08-08 17:15:23 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
switch(position)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
switch(titlebar->position)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
case Floating:
|
|
|
|
tmp = titlebar->sw.geometry.width;
|
|
|
|
titlebar->sw.geometry.width = titlebar->sw.geometry.height;
|
|
|
|
titlebar->sw.geometry.height = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
simplewindow_orientation_set(&titlebar->sw, North);
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
switch(titlebar->position)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
case Floating:
|
|
|
|
tmp = titlebar->sw.geometry.width;
|
|
|
|
titlebar->sw.geometry.width = titlebar->sw.geometry.height;
|
|
|
|
titlebar->sw.geometry.height = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
simplewindow_orientation_set(&titlebar->sw, South);
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
case Floating:
|
|
|
|
switch(titlebar->position)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
tmp = titlebar->sw.geometry.width;
|
|
|
|
titlebar->sw.geometry.width = titlebar->sw.geometry.height;
|
|
|
|
titlebar->sw.geometry.height = tmp;
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
case Floating:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
simplewindow_orientation_set(&titlebar->sw, East);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-21 20:39:23 +02:00
|
|
|
titlebar->position = position;
|
2008-09-24 12:13:21 +02:00
|
|
|
if((c = client_getbytitlebar(titlebar)))
|
|
|
|
{
|
|
|
|
titlebar_update_geometry_floating(c);
|
|
|
|
/* call geometry hook for client because some like to
|
|
|
|
* set titlebar width in that hook, which make sense */
|
|
|
|
hooks_property(c, "geometry");
|
|
|
|
}
|
2008-08-08 17:15:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-07-01 18:19:33 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
if((c || (c = client_getbytitlebar(titlebar))))
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(c);
|
2008-07-01 18:28:17 +02:00
|
|
|
|
2008-07-01 18:19:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
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[] =
|
|
|
|
{
|
|
|
|
{ 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
|