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
|
|
|
}
|
|
|
|
|
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. */
|
|
|
|
if(titlebar)
|
|
|
|
{
|
|
|
|
simple_window_t *sw = &titlebar->sw;
|
|
|
|
|
|
|
|
if(sw->window)
|
|
|
|
{
|
|
|
|
uint32_t request[] = { - sw->geometry.width, - sw->geometry.height };
|
|
|
|
/* Move the titlebar to the same place as the window. */
|
|
|
|
xcb_configure_window(globalconf.connection, sw->window,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-02-02 20:16:57 +01:00
|
|
|
res->y = geometry.y - c->titlebar->sw.geometry.height;
|
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-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;
|
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-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 - c->titlebar->sw.geometry.width;
|
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-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;
|
2008-09-24 12:13:21 +02:00
|
|
|
res->width = c->titlebar->sw.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)
|
|
|
|
{
|
|
|
|
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-11-14 10:02:10 +01:00
|
|
|
wibox_unref(&c->titlebar);
|
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;
|
2009-02-02 20:16:57 +01:00
|
|
|
/* Get geometry prior to any titlebar changes. */
|
|
|
|
area_t curgeom = titlebar_geometry_remove(c->titlebar, 0, c->geometry);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-02-02 20:16:57 +01:00
|
|
|
/* Client geometry without titlebar, but including borders, since that is always consistent. */
|
|
|
|
titlebar_geometry_compute(c, curgeom, &wingeom);
|
2008-09-24 12:13:21 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-02-05 17:55:59 +01: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);
|
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
if (visible != t->isvisible)
|
|
|
|
{
|
|
|
|
/* The price of (un)mapping something small like a titlebar is pretty cheap.
|
|
|
|
* It would complicate matters if this rare case was treated like clients.
|
|
|
|
* Clients are moved out of the viewport when banned.
|
|
|
|
*/
|
|
|
|
if ((t->isvisible = visible))
|
|
|
|
xcb_map_window(globalconf.connection, t->sw.window);
|
|
|
|
else
|
|
|
|
xcb_unmap_window(globalconf.connection, t->sw.window);
|
|
|
|
|
|
|
|
globalconf.screens[t->screen].need_arrange = true;
|
|
|
|
client_stack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)))
|
2008-09-29 17:29:21 +02:00
|
|
|
simplewindow_border_color_set(&titlebar->sw, &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)))
|
|
|
|
{
|
2008-11-25 17:01:06 +01:00
|
|
|
titlebar_update_geometry(c);
|
2008-09-24 12:13:21 +02:00
|
|
|
/* 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-03-15 13:59:04 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|