2008-03-15 13:59:04 +01:00
|
|
|
/*
|
|
|
|
* titlebar.c - titlebar management
|
|
|
|
*
|
2009-08-17 16:38:56 +02:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-03-15 13:59:04 +01:00
|
|
|
*
|
|
|
|
* 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"
|
2009-09-14 20:22:12 +02:00
|
|
|
#include "objects/client.h"
|
2009-09-14 20:26:33 +02:00
|
|
|
#include "objects/widget.h"
|
2008-09-21 10:13:21 +02:00
|
|
|
#include "wibox.h"
|
2008-09-24 12:13:21 +02:00
|
|
|
#include "screen.h"
|
2009-08-17 16:38:56 +02:00
|
|
|
#include "luaa.h"
|
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
|
|
|
{
|
2009-04-09 17:17:10 +02:00
|
|
|
foreach(c, globalconf.clients)
|
|
|
|
if((*c)->titlebar == titlebar)
|
|
|
|
return *c;
|
2008-06-04 17:54:52 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-04-09 17:17:10 +02:00
|
|
|
foreach(c, globalconf.clients)
|
2009-07-28 16:04:58 +02:00
|
|
|
if((*c)->titlebar && (*c)->titlebar->window == win)
|
2009-04-09 17:17:10 +02:00
|
|
|
return *c;
|
2008-06-03 18:41:54 +02:00
|
|
|
|
|
|
|
return NULL;
|
2008-03-25 14:45:13 +01:00
|
|
|
}
|
|
|
|
|
2009-02-05 17:55:59 +01:00
|
|
|
/** Move a titlebar out of the viewport.
|
|
|
|
* \param titlebar The titlebar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_ban(wibox_t *titlebar)
|
|
|
|
{
|
|
|
|
/* Do it manually because client geometry remains unchanged. */
|
2009-03-26 22:13:42 +01:00
|
|
|
if(titlebar && !titlebar->isbanned)
|
2009-02-05 17:55:59 +01:00
|
|
|
{
|
2009-03-26 22:13:42 +01:00
|
|
|
client_t *c;
|
2009-02-05 17:55:59 +01:00
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
if(titlebar->window)
|
|
|
|
xcb_unmap_window(globalconf.connection, titlebar->window);
|
2009-03-26 22:13:42 +01:00
|
|
|
|
|
|
|
/* Remove titlebar geometry from client. */
|
2009-03-29 20:26:39 +02:00
|
|
|
if((c = client_getbytitlebar(titlebar)))
|
2009-03-26 22:13:42 +01:00
|
|
|
c->geometry = titlebar_geometry_remove(titlebar, 0, c->geometry);
|
|
|
|
|
|
|
|
titlebar->isbanned = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Move a titlebar on top of its client.
|
|
|
|
* \param titlebar The titlebar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_unban(wibox_t *titlebar)
|
|
|
|
{
|
|
|
|
/* Do this manually because the system doesn't know we moved the toolbar.
|
2009-08-17 16:56:03 +02:00
|
|
|
* Note that !visible titlebars are unmapped and for fullscreen it'll
|
2009-03-26 22:13:42 +01:00
|
|
|
* end up offscreen anyway. */
|
|
|
|
if(titlebar && titlebar->isbanned)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
if(titlebar->window)
|
|
|
|
xcb_map_window(globalconf.connection, titlebar->window);
|
2009-03-26 22:13:42 +01:00
|
|
|
|
|
|
|
titlebar->isbanned = false;
|
|
|
|
|
|
|
|
/* Add titlebar geometry from client. */
|
2009-03-29 20:26:39 +02:00
|
|
|
if((c = client_getbytitlebar(titlebar)))
|
2009-03-26 22:13:42 +01:00
|
|
|
c->geometry = titlebar_geometry_add(titlebar, 0, c->geometry);
|
2009-02-05 17:55:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-02 20:16:57 +01:00
|
|
|
/** Get titlebar area.
|
|
|
|
* \param c The client
|
|
|
|
* \param geometry The client geometry including borders, excluding titlebars.
|
|
|
|
* \param res Pointer to area of titlebar, must be allocated already.
|
|
|
|
*/
|
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-12-12 00:01:43 +01:00
|
|
|
int height, 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-12-12 00:01:43 +01:00
|
|
|
width = MAX(1, geometry.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-12-12 00:01:43 +01:00
|
|
|
x_offset = geometry.width - 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;
|
2009-07-28 16:04:58 +02:00
|
|
|
res->y = geometry.y - c->titlebar->geometry.height;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->width = width;
|
2009-07-28 16:04:58 +02:00
|
|
|
res->height = c->titlebar->geometry.height;
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-12-12 00:01:43 +01:00
|
|
|
width = MAX(1, geometry.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-12-12 00:01:43 +01:00
|
|
|
x_offset = geometry.width - 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;
|
2009-02-02 20:16:57 +01:00
|
|
|
res->y = geometry.y + geometry.height;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->width = width;
|
2009-07-28 16:04:58 +02:00
|
|
|
res->height = c->titlebar->geometry.height;
|
2008-03-15 14:19:52 +01:00
|
|
|
break;
|
2008-03-15 20:10:09 +01:00
|
|
|
case Left:
|
2008-12-12 00:01:43 +01:00
|
|
|
height = MAX(1, geometry.height);
|
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-12-12 00:01:43 +01:00
|
|
|
y_offset = geometry.height - height;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-12-12 00:01:43 +01:00
|
|
|
y_offset = (geometry.height - height) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-07-28 16:04:58 +02:00
|
|
|
res->x = geometry.x - c->titlebar->geometry.width;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->y = geometry.y + y_offset;
|
2009-07-28 16:04:58 +02:00
|
|
|
res->width = c->titlebar->geometry.width;
|
2008-12-12 00:01:43 +01:00
|
|
|
res->height = height;
|
2008-03-15 20:10:09 +01:00
|
|
|
break;
|
2008-03-16 18:00:49 +01:00
|
|
|
case Right:
|
2008-12-12 00:01:43 +01:00
|
|
|
height = MAX(1, geometry.height);
|
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-12-12 00:01:43 +01:00
|
|
|
y_offset = geometry.height - height;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
case AlignCenter:
|
2008-12-12 00:01:43 +01:00
|
|
|
y_offset = (geometry.height - height) / 2;
|
2008-03-24 17:42:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-02 20:16:57 +01:00
|
|
|
res->x = geometry.x + geometry.width;
|
2008-06-18 11:22:54 +02:00
|
|
|
res->y = geometry.y + y_offset;
|
2009-07-28 16:04:58 +02:00
|
|
|
res->width = c->titlebar->geometry.width;
|
2008-12-12 00:01:43 +01:00
|
|
|
res->height = height;
|
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
|
|
|
/** 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)
|
|
|
|
{
|
2009-02-06 19:13:20 +01:00
|
|
|
/* Update client geometry to exclude the titlebar. */
|
|
|
|
c->geometry = titlebar_geometry_remove(c->titlebar, 0, c->geometry);
|
2009-07-28 16:04:58 +02:00
|
|
|
wibox_wipe(c->titlebar);
|
2008-09-24 12:13:21 +02:00
|
|
|
c->titlebar->type = WIBOX_TYPE_NORMAL;
|
2009-04-17 16:14:09 +02:00
|
|
|
c->titlebar->screen = NULL;
|
2009-04-11 00:27:06 +02:00
|
|
|
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_unref(globalconf.L, c->titlebar);
|
2008-09-21 20:39:23 +02:00
|
|
|
c->titlebar = NULL;
|
2009-04-11 00:27:06 +02:00
|
|
|
|
2009-08-28 17:04:59 +02:00
|
|
|
luaA_object_push(globalconf.L, c);
|
|
|
|
luaA_object_emit_signal(globalconf.L, -1, "property::titlebar", 0);
|
|
|
|
lua_pop(globalconf.L, 1);
|
2008-09-21 20:39:23 +02:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void
|
2009-04-11 00:27:06 +02:00
|
|
|
titlebar_client_attach(client_t *c)
|
2008-09-21 20:39:23 +02:00
|
|
|
{
|
2009-04-11 00:27:06 +02:00
|
|
|
/* check if we can register the object */
|
2009-09-04 12:46:20 +02:00
|
|
|
wibox_t *t = luaA_object_ref_class(globalconf.L, -1, &wibox_class);
|
2009-04-11 00:27:06 +02:00
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
titlebar_client_detach(c);
|
2008-08-12 14:53:57 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* check if titlebar is already on a client */
|
|
|
|
titlebar_client_detach(client_getbytitlebar(t));
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* check if client already has a titlebar. */
|
|
|
|
titlebar_client_detach(c);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* set the object as new client's titlebar */
|
|
|
|
c->titlebar = t;
|
2009-02-06 19:13:20 +01:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
t->type = WIBOX_TYPE_TITLEBAR;
|
|
|
|
t->screen = c->screen;
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
switch(t->position)
|
|
|
|
{
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2009-07-28 16:04:58 +02:00
|
|
|
if(!t->geometry.height)
|
|
|
|
t->geometry.height = 1.5 * globalconf.font->height;
|
2009-04-11 00:27:06 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
2009-07-28 16:04:58 +02:00
|
|
|
if(!t->geometry.width)
|
|
|
|
t->geometry.width = 1.5 * globalconf.font->height;
|
2009-04-11 00:27:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* Update client geometry to include the titlebar. */
|
|
|
|
c->geometry = titlebar_geometry_add(c->titlebar, 0, c->geometry);
|
2009-02-06 19:13:20 +01:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* Client geometry without titlebar, but including borders, since that is always consistent. */
|
2009-07-28 16:04:58 +02:00
|
|
|
titlebar_geometry_compute(c, titlebar_geometry_remove(c->titlebar, 0, c->geometry), &t->geometry);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
wibox_init(t, c->phys_screen);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
t->need_update = true;
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-04-11 00:27:06 +02:00
|
|
|
/* Call update geometry. This will move the wibox to the right place,
|
|
|
|
* which might be the same as `wingeom', but then it will ban the
|
|
|
|
* titlebar if needed. */
|
|
|
|
titlebar_update_geometry(c);
|
2009-02-05 17:55:59 +01:00
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
xcb_map_window(globalconf.connection, t->window);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
2009-08-28 11:54:22 +02:00
|
|
|
luaA_object_push(globalconf.L, c);
|
|
|
|
luaA_object_emit_signal(globalconf.L, -1, "property::titlebar", 0);
|
|
|
|
lua_pop(globalconf.L, 1);
|
2009-04-11 00:27:06 +02:00
|
|
|
client_stack();
|
2008-03-15 13:59:04 +01:00
|
|
|
}
|
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/** Map or unmap a titlebar wibox.
|
|
|
|
* \param t The wibox/titlebar.
|
|
|
|
* \param visible The new state of the titlebar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
titlebar_set_visible(wibox_t *t, bool visible)
|
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
if(visible != t->visible)
|
2008-11-20 22:11:13 +01:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
if((t->visible = visible))
|
2009-03-26 22:13:42 +01:00
|
|
|
titlebar_unban(t);
|
2008-11-20 22:11:13 +01:00
|
|
|
else
|
2009-03-26 22:13:42 +01:00
|
|
|
titlebar_ban(t);
|
2008-11-20 22:11:13 +01:00
|
|
|
|
|
|
|
client_stack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-21 20:39:23 +02:00
|
|
|
int
|
2009-08-17 16:56:03 +02:00
|
|
|
luaA_titlebar_set_position(lua_State *L, int udx)
|
2008-07-01 18:19:33 +02:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
wibox_t *titlebar = luaA_checkudata(L, udx, &wibox_class);
|
|
|
|
size_t len;
|
|
|
|
const char *buf = luaL_checklstring(L, -1, &len);
|
|
|
|
position_t position = position_fromstr(buf, len);
|
|
|
|
if(position != titlebar->position)
|
2008-07-01 18:19:33 +02:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
switch(position)
|
2008-08-08 17:15:23 +02:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
case Left:
|
|
|
|
switch(titlebar->position)
|
2008-09-24 12:13:21 +02:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
int tmp;
|
2008-09-24 12:13:21 +02:00
|
|
|
case Left:
|
2009-08-17 16:56:03 +02:00
|
|
|
case Right:
|
2008-09-24 12:13:21 +02:00
|
|
|
break;
|
2009-08-17 16:56:03 +02:00
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
tmp = titlebar->geometry.width;
|
|
|
|
titlebar->geometry.width = titlebar->geometry.height;
|
|
|
|
titlebar->geometry.height = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wibox_set_orientation(L, udx, North);
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
switch(titlebar->position)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
case Left:
|
2008-09-24 12:13:21 +02:00
|
|
|
case Right:
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
2009-08-17 16:56:03 +02:00
|
|
|
tmp = titlebar->geometry.width;
|
|
|
|
titlebar->geometry.width = titlebar->geometry.height;
|
|
|
|
titlebar->geometry.height = tmp;
|
2008-09-24 12:13:21 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-08-17 16:56:03 +02:00
|
|
|
wibox_set_orientation(L, udx, South);
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
switch(titlebar->position)
|
2008-09-24 12:13:21 +02:00
|
|
|
{
|
2009-08-17 16:56:03 +02:00
|
|
|
int tmp;
|
|
|
|
case Left:
|
|
|
|
case Right:
|
|
|
|
tmp = titlebar->geometry.width;
|
|
|
|
titlebar->geometry.width = titlebar->geometry.height;
|
|
|
|
titlebar->geometry.height = tmp;
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
case Bottom:
|
|
|
|
break;
|
2008-09-24 12:13:21 +02:00
|
|
|
}
|
2009-08-17 16:56:03 +02:00
|
|
|
wibox_set_orientation(L, udx, East);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
titlebar->position = position;
|
|
|
|
client_t *c;
|
|
|
|
if((c = client_getbytitlebar(titlebar)))
|
|
|
|
titlebar_update_geometry(c);
|
2008-07-01 18:19:33 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-15 13:59:04 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|