Split titlebar stuff into titlebar.[ch], and uicb_client_toggletitlebar

This commit is contained in:
Julien Danjou 2008-03-15 13:59:04 +01:00
parent bc6656320d
commit 9bd32fc3b8
12 changed files with 161 additions and 67 deletions

View File

@ -121,6 +121,7 @@ awesome_SOURCES = \
common/list.h \ common/list.h \
structs.h \ structs.h \
client.c client.h \ client.c client.h \
titlebar.c titlebar.h \
placement.c placement.h \ placement.c placement.h \
focus.c focus.h \ focus.c focus.h \
common/draw.c common/draw.h \ common/draw.c common/draw.h \

View File

@ -301,6 +301,8 @@ Client
Set or unset client as being the scratch window. Set or unset client as being the scratch window.
*client_togglescratch*:: *client_togglescratch*::
Toggle scratch window. Toggle scratch window.
*client_toggletitlebar*::
Toggle window titlebar.
Tag Tag
~~~ ~~~

View File

@ -31,6 +31,7 @@
#include "ewmh.h" #include "ewmh.h"
#include "widget.h" #include "widget.h"
#include "screen.h" #include "screen.h"
#include "titlebar.h"
#include "layouts/floating.h" #include "layouts/floating.h"
#include "common/xutil.h" #include "common/xutil.h"
#include "common/xscreen.h" #include "common/xscreen.h"
@ -132,39 +133,6 @@ client_get_byname(Client *list, char *name)
return NULL; return NULL;
} }
void
client_updatetitlebar(Client *c)
{
DrawCtx *ctx;
int phys_screen;
style_t style;
area_t geometry;
if(!c->titlebar.position)
return;
phys_screen = get_phys_screen(c->screen);
ctx = draw_context_new(globalconf.display, phys_screen,
c->titlebar.sw->geometry.width,
c->titlebar.sw->geometry.height,
c->titlebar.sw->drawable);
style = globalconf.focus->client == c ?
globalconf.screens[c->screen].styles.focus :
globalconf.screens[c->screen].styles.normal;
geometry = c->titlebar.sw->geometry;
geometry.x = geometry.y = 0;
draw_text(ctx, geometry, c->titlebar.text_align, style.font->height / 2,
c->name, style);
simplewindow_refresh_drawable(c->titlebar.sw, phys_screen);
draw_context_delete(ctx);
}
/** Update client name attribute with its title /** Update client name attribute with its title
* \param c the client * \param c the client
*/ */
@ -176,7 +144,7 @@ client_updatetitle(Client *c)
xgettextprop(globalconf.display, c->win, xgettextprop(globalconf.display, c->win,
XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name)); XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
client_updatetitlebar(c); titlebar_update(c);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
@ -190,7 +158,7 @@ client_unfocus(Client *c)
XSetWindowBorder(globalconf.display, c->win, XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[c->screen].styles.normal.border.pixel); globalconf.screens[c->screen].styles.normal.border.pixel);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
client_updatetitlebar(c); titlebar_update(c);
} }
/** Ban client and unmap it /** Ban client and unmap it
@ -239,7 +207,7 @@ client_focus(Client *c, int screen, Bool raise)
window_settrans(c->win, -1); window_settrans(c->win, -1);
XSetWindowBorder(globalconf.display, c->win, XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[screen].styles.focus.border.pixel); globalconf.screens[screen].styles.focus.border.pixel);
client_updatetitlebar(c); titlebar_update(c);
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
if(raise) if(raise)
{ {
@ -486,25 +454,6 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
ewmh_update_net_client_list(phys_screen); ewmh_update_net_client_list(phys_screen);
} }
area_t
client_titlebar_update_geometry(Client *c, area_t geometry)
{
if(!c->titlebar.position)
return geometry;;
simplewindow_move_resize(c->titlebar.sw,
geometry.x,
geometry.y,
geometry.width,
c->titlebar.sw->geometry.height);
client_updatetitlebar(c);
geometry.y += c->titlebar.sw->geometry.height;
geometry.height -= c->titlebar.sw->geometry.height;
return geometry;
}
area_t area_t
client_geometry_hints(Client *c, area_t geometry) client_geometry_hints(Client *c, area_t geometry)
{ {
@ -612,7 +561,7 @@ client_resize(Client *c, area_t geometry)
default: default:
break; break;
} }
client_updatetitlebar(c); titlebar_update(c);
} }
} }
@ -1234,4 +1183,5 @@ uicb_client_togglescratch(int screen,
widget_invalidate_cache(globalconf.scratch.client->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(globalconf.scratch.client->screen, WIDGET_CACHE_CLIENTS);
} }
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -31,13 +31,11 @@ void client_focus(Client *, int, Bool);
void client_ban(Client *); void client_ban(Client *);
void client_unban(Client *); void client_unban(Client *);
void client_manage(Window, XWindowAttributes *, int); void client_manage(Window, XWindowAttributes *, int);
area_t client_titlebar_update_geometry(Client *, area_t);
area_t client_geometry_hints(Client *, area_t); area_t client_geometry_hints(Client *, area_t);
Bool client_resize(Client *, area_t); Bool client_resize(Client *, area_t);
void client_unmanage(Client *); void client_unmanage(Client *);
void client_updatewmhints(Client *); void client_updatewmhints(Client *);
long client_updatesizehints(Client *); long client_updatesizehints(Client *);
void client_updatetitlebar(Client *);
void client_updatetitle(Client *); void client_updatetitle(Client *);
void client_saveprops(Client *); void client_saveprops(Client *);
void client_kill(Client *); void client_kill(Client *);

View File

@ -275,7 +275,8 @@ create_widgets(cfg_t* cfg_statusbar, Statusbar *statusbar)
static void static void
config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb) config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb)
{ {
tb->position = position_get_from_str(cfg_getstr(cfg_titlebar, "position")); tb->position = tb->dposition =
position_get_from_str(cfg_getstr(cfg_titlebar, "position"));
tb->icon = position_get_from_str(cfg_getstr(cfg_titlebar, "icon")); tb->icon = position_get_from_str(cfg_getstr(cfg_titlebar, "icon"));
tb->text_align = draw_get_align(cfg_getstr(cfg_titlebar, "text_align")); tb->text_align = draw_get_align(cfg_getstr(cfg_titlebar, "text_align"));
} }

View File

@ -22,6 +22,7 @@
#include "screen.h" #include "screen.h"
#include "tag.h" #include "tag.h"
#include "client.h" #include "client.h"
#include "titlebar.h"
#include "layouts/fibonacci.h" #include "layouts/fibonacci.h"
#include "common/util.h" #include "common/util.h"
@ -85,10 +86,10 @@ layout_fibonacci(int screen, int shape)
if(globalconf.screens[screen].resize_hints) if(globalconf.screens[screen].resize_hints)
client_resize(c, client_resize(c,
client_geometry_hints(c, client_geometry_hints(c,
client_titlebar_update_geometry(c, titlebar_update_geometry(c,
geometry))); geometry)));
else else
client_resize(c, client_titlebar_update_geometry(c, geometry)); client_resize(c, titlebar_update_geometry(c, geometry));
geometry.width += 2 * c->border; geometry.width += 2 * c->border;
geometry.height += 2 * c->border; geometry.height += 2 * c->border;
} }

View File

@ -22,6 +22,7 @@
#include "tag.h" #include "tag.h"
#include "screen.h" #include "screen.h"
#include "client.h" #include "client.h"
#include "titlebar.h"
#include "layouts/max.h" #include "layouts/max.h"
#include "common/util.h" #include "common/util.h"
@ -43,10 +44,10 @@ layout_max(int screen)
if(globalconf.screens[screen].resize_hints) if(globalconf.screens[screen].resize_hints)
client_resize(c, client_resize(c,
client_geometry_hints(c, client_geometry_hints(c,
client_titlebar_update_geometry(c, titlebar_update_geometry(c,
area))); area)));
else else
client_resize(c, client_titlebar_update_geometry(c, area)); client_resize(c, titlebar_update_geometry(c, area));
area.width += 2 * c->border; area.width += 2 * c->border;
area.height += 2 * c->border; area.height += 2 * c->border;
} }

View File

@ -26,6 +26,7 @@
#include "tag.h" #include "tag.h"
#include "layout.h" #include "layout.h"
#include "client.h" #include "client.h"
#include "titlebar.h"
#include "layouts/tile.h" #include "layouts/tile.h"
#include "common/util.h" #include "common/util.h"
@ -207,7 +208,7 @@ _tile(int screen, const Position position)
geometry.width = mw - 2 * c->border; geometry.width = mw - 2 * c->border;
geometry.height = mh - 2 * c->border; geometry.height = mh - 2 * c->border;
geometry = client_titlebar_update_geometry(c, geometry); geometry = titlebar_update_geometry(c, geometry);
if(globalconf.screens[screen].resize_hints) if(globalconf.screens[screen].resize_hints)
geometry = client_geometry_hints(c, geometry); geometry = client_geometry_hints(c, geometry);
@ -263,7 +264,7 @@ _tile(int screen, const Position position)
geometry.y += mh; geometry.y += mh;
} }
geometry = client_titlebar_update_geometry(c, geometry); geometry = titlebar_update_geometry(c, geometry);
if(globalconf.screens[screen].resize_hints) if(globalconf.screens[screen].resize_hints)
geometry = client_geometry_hints(c, geometry); geometry = client_geometry_hints(c, geometry);

View File

@ -44,6 +44,7 @@ typedef struct
{ {
SimpleWindow *sw; SimpleWindow *sw;
Position position; Position position;
Position dposition;
Alignment text_align; Alignment text_align;
Position icon; Position icon;
} Titlebar; } Titlebar;

104
titlebar.c Normal file
View File

@ -0,0 +1,104 @@
/*
* 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.
*
*/
#include "titlebar.h"
extern AwesomeConf globalconf;
void
titlebar_update(Client *c)
{
DrawCtx *ctx;
style_t style;
area_t geometry;
if(!c->titlebar.position)
return;
ctx = draw_context_new(globalconf.display, c->titlebar.sw->phys_screen,
c->titlebar.sw->geometry.width,
c->titlebar.sw->geometry.height,
c->titlebar.sw->drawable);
if(c->isurgent)
style = globalconf.screens[c->screen].styles.urgent;
else if(globalconf.focus->client == c)
style = globalconf.screens[c->screen].styles.focus;
else
style = globalconf.screens[c->screen].styles.normal;
geometry = c->titlebar.sw->geometry;
geometry.x = geometry.y = 0;
draw_text(ctx, geometry, c->titlebar.text_align, style.font->height / 2,
c->name, style);
simplewindow_refresh_drawable(c->titlebar.sw, c->titlebar.sw->phys_screen);
draw_context_delete(ctx);
}
area_t
titlebar_update_geometry(Client *c, area_t geometry)
{
if(!c->titlebar.position)
return geometry;;
simplewindow_move_resize(c->titlebar.sw,
geometry.x,
geometry.y,
geometry.width,
c->titlebar.sw->geometry.height);
titlebar_update(c);
geometry.y += c->titlebar.sw->geometry.height;
geometry.height -= c->titlebar.sw->geometry.height;
return geometry;
}
/** Toggle window titlebar visibility
* \param screen screen number (unused)
* \param arg unused argument
* \ingroup ui_callback
*/
void
uicb_client_toggletitlebar(int screen __attribute__ ((unused)),
char *arg __attribute__ ((unused)))
{
Client *c = globalconf.focus->client;
if(!c->titlebar.sw)
return;
if(!c->titlebar.position)
c->titlebar.position = c->titlebar.dposition;
else
{
c->titlebar.position = Off;
XUnmapWindow(globalconf.display, c->titlebar.sw->window);
}
globalconf.screens[c->screen].need_arrange = True;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

33
titlebar.h Normal file
View File

@ -0,0 +1,33 @@
/*
* titlebar.h - titlebar management header
*
* 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.
*
*/
#ifndef AWESOME_TITLEBAR_H
#define AWESOME_TITLEBAR_H
#include "structs.h"
void titlebar_update(Client *);
area_t titlebar_update_geometry(Client *, area_t);
Uicb uicb_client_toggletitlebar;
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

1
uicb.c
View File

@ -37,6 +37,7 @@
#include "focus.h" #include "focus.h"
#include "client.h" #include "client.h"
#include "screen.h" #include "screen.h"
#include "titlebar.h"
#include "layouts/tile.h" #include "layouts/tile.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;