feat: implement <font place="InactiveWindow"> (ref scope: 2.4.7) (#1292)

* feat: implement <font place="InactiveWindow"> (ref scope: 2.4.7)
* docs: add inactivewindow
This commit is contained in:
Ludgie 2023-12-07 09:28:27 +01:00 committed by GitHub
parent d59b1d0966
commit b34d074063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 3 deletions

View file

@ -238,6 +238,7 @@ windows using the mouse.
The font to use for a specific element of a window, menu or OSD. The font to use for a specific element of a window, menu or OSD.
Places can be any of: Places can be any of:
- ActiveWindow - titlebar of active window - ActiveWindow - titlebar of active window
- InactiveWindow - titlebar of all windows that aren't focused by the cursor
- MenuItem - menu item (currently only root menu) - MenuItem - menu item (currently only root menu)
- OnScreenDisplay - items in the on screen display - OnScreenDisplay - items in the on screen display
If no place attribute is provided, the setting will be applied to all If no place attribute is provided, the setting will be applied to all

View file

@ -25,6 +25,12 @@
<slant>normal</slant> <slant>normal</slant>
<weight>normal</weight> <weight>normal</weight>
</font> </font>
<font place="InactiveWindow">
<name>sans</name>
<size>10</size>
<slant>normal</slant>
<weight>normal</weight>
</font>
<font place="MenuItem"> <font place="MenuItem">
<name>sans</name> <name>sans</name>
<size>10</size> <size>10</size>

View file

@ -51,6 +51,7 @@ struct rcxml {
int corner_radius; int corner_radius;
bool ssd_keep_border; bool ssd_keep_border;
struct font font_activewindow; struct font font_activewindow;
struct font font_inactivewindow;
struct font font_menuitem; struct font font_menuitem;
struct font font_osd; struct font font_osd;
/* Pointer to current theme */ /* Pointer to current theme */

View file

@ -61,6 +61,7 @@ enum font_place {
FONT_PLACE_NONE = 0, FONT_PLACE_NONE = 0,
FONT_PLACE_UNKNOWN, FONT_PLACE_UNKNOWN,
FONT_PLACE_ACTIVEWINDOW, FONT_PLACE_ACTIVEWINDOW,
FONT_PLACE_INACTIVEWINDOW,
FONT_PLACE_MENUITEM, FONT_PLACE_MENUITEM,
FONT_PLACE_OSD, FONT_PLACE_OSD,
/* TODO: Add all places based on Openbox's rc.xml */ /* TODO: Add all places based on Openbox's rc.xml */
@ -564,12 +565,16 @@ fill_font(char *nodename, char *content, enum font_place place)
* attribute, we set all font variables * attribute, we set all font variables
*/ */
set_font_attr(&rc.font_activewindow, nodename, content); set_font_attr(&rc.font_activewindow, nodename, content);
set_font_attr(&rc.font_inactivewindow, nodename, content);
set_font_attr(&rc.font_menuitem, nodename, content); set_font_attr(&rc.font_menuitem, nodename, content);
set_font_attr(&rc.font_osd, nodename, content); set_font_attr(&rc.font_osd, nodename, content);
break; break;
case FONT_PLACE_ACTIVEWINDOW: case FONT_PLACE_ACTIVEWINDOW:
set_font_attr(&rc.font_activewindow, nodename, content); set_font_attr(&rc.font_activewindow, nodename, content);
break; break;
case FONT_PLACE_INACTIVEWINDOW:
set_font_attr(&rc.font_inactivewindow, nodename, content);
break;
case FONT_PLACE_MENUITEM: case FONT_PLACE_MENUITEM:
set_font_attr(&rc.font_menuitem, nodename, content); set_font_attr(&rc.font_menuitem, nodename, content);
break; break;
@ -592,6 +597,8 @@ enum_font_place(const char *place)
} }
if (!strcasecmp(place, "ActiveWindow")) { if (!strcasecmp(place, "ActiveWindow")) {
return FONT_PLACE_ACTIVEWINDOW; return FONT_PLACE_ACTIVEWINDOW;
} else if (!strcasecmp(place, "InactiveWindow")) {
return FONT_PLACE_INACTIVEWINDOW;
} else if (!strcasecmp(place, "MenuItem")) { } else if (!strcasecmp(place, "MenuItem")) {
return FONT_PLACE_MENUITEM; return FONT_PLACE_MENUITEM;
} else if (!strcasecmp(place, "OnScreenDisplay") } else if (!strcasecmp(place, "OnScreenDisplay")
@ -949,6 +956,7 @@ rcxml_init(void)
rc.corner_radius = 8; rc.corner_radius = 8;
init_font_defaults(&rc.font_activewindow); init_font_defaults(&rc.font_activewindow);
init_font_defaults(&rc.font_inactivewindow);
init_font_defaults(&rc.font_menuitem); init_font_defaults(&rc.font_menuitem);
init_font_defaults(&rc.font_osd); init_font_defaults(&rc.font_osd);
@ -1256,6 +1264,9 @@ post_processing(void)
if (!rc.font_activewindow.name) { if (!rc.font_activewindow.name) {
rc.font_activewindow.name = xstrdup("sans"); rc.font_activewindow.name = xstrdup("sans");
} }
if (!rc.font_inactivewindow.name) {
rc.font_inactivewindow.name = xstrdup("sans");
}
if (!rc.font_menuitem.name) { if (!rc.font_menuitem.name) {
rc.font_menuitem.name = xstrdup("sans"); rc.font_menuitem.name = xstrdup("sans");
} }
@ -1440,6 +1451,7 @@ void
rcxml_finish(void) rcxml_finish(void)
{ {
zfree(rc.font_activewindow.name); zfree(rc.font_activewindow.name);
zfree(rc.font_inactivewindow.name);
zfree(rc.font_menuitem.name); zfree(rc.font_menuitem.name);
zfree(rc.font_osd.name); zfree(rc.font_osd.name);
zfree(rc.theme_name); zfree(rc.theme_name);

View file

@ -317,6 +317,7 @@ ssd_update_title(struct ssd *ssd)
bool title_unchanged = state->text && !strcmp(title, state->text); bool title_unchanged = state->text && !strcmp(title, state->text);
float *text_color; float *text_color;
struct font *font = NULL;
struct ssd_part *part; struct ssd_part *part;
struct ssd_sub_tree *subtree; struct ssd_sub_tree *subtree;
struct ssd_state_title_width *dstate; struct ssd_state_title_width *dstate;
@ -327,9 +328,11 @@ ssd_update_title(struct ssd *ssd)
if (subtree == &ssd->titlebar.active) { if (subtree == &ssd->titlebar.active) {
dstate = &state->active; dstate = &state->active;
text_color = theme->window_active_label_text_color; text_color = theme->window_active_label_text_color;
font = &rc.font_activewindow;
} else { } else {
dstate = &state->inactive; dstate = &state->inactive;
text_color = theme->window_inactive_label_text_color; text_color = theme->window_inactive_label_text_color;
font = &rc.font_inactivewindow;
} }
if (title_bg_width <= 0) { if (title_bg_width <= 0) {
@ -356,9 +359,8 @@ ssd_update_title(struct ssd *ssd)
} }
if (part->buffer) { if (part->buffer) {
/* TODO: Do we only have active window fonts? */
scaled_font_buffer_update(part->buffer, title, scaled_font_buffer_update(part->buffer, title,
title_bg_width, &rc.font_activewindow, title_bg_width, font,
text_color, NULL); text_color, NULL);
} }

View file

@ -848,7 +848,7 @@ create_corners(struct theme *theme)
static void static void
post_processing(struct theme *theme) post_processing(struct theme *theme)
{ {
int h = font_height(&rc.font_activewindow); int h = MAX(font_height(&rc.font_activewindow), font_height(&rc.font_inactivewindow));
if (theme->title_height < h) { if (theme->title_height < h) {
theme->title_height = h + 2 * theme->padding_height; theme->title_height = h + 2 * theme->padding_height;
} }