allow app rules to match windows by their title when mapping

and save the title in the _OB_APP_TITLE property
This commit is contained in:
Dana Jansens 2010-01-14 17:24:39 -05:00
parent ae85462f2b
commit 6cf3357036
8 changed files with 35 additions and 15 deletions

View file

@ -693,18 +693,19 @@
<!-- <!--
# this is an example with comments through out. use these to make your # this is an example with comments through out. use these to make your
# own rules, but without the comments of course. # own rules, but without the comments of course.
# you may use one or more of the name/class/role/type rules to specify # you may use one or more of the name/class/role/title/type rules to specify
# windows to match # windows to match
<application name="the window's _OB_APP_NAME property (see obxprop)" <application name="the window's _OB_APP_NAME property (see obxprop)"
class="the window's _OB_APP_CLASS property (see obxprop)" class="the window's _OB_APP_CLASS property (see obxprop)"
role="the window's _OB_APP_ROLE property (see obxprop)" role="the window's _OB_APP_ROLE property (see obxprop)"
title="the window's _OB_APP_TITLE property (see obxprop)"
type="the window's _OB_APP_TYPE property (see obxprob).. type="the window's _OB_APP_TYPE property (see obxprob)..
(if unspecified, then it is 'dialog' for child windows)"> (if unspecified, then it is 'dialog' for child windows)">
# you may set only one of name/class/role/type, or you may use more than one # you may set only one of name/class/role/title/type, or you may use more
# together to restrict your matches. # than one together to restrict your matches.
# the name, class, and role use simple wildcard matching such as those # the name, class, role, and title use simple wildcard matching such as those
# used by a shell. you can use * to match any characters and ? to match # used by a shell. you can use * to match any characters and ? to match
# any single character. # any single character.

View file

@ -246,9 +246,10 @@
<xsd:element minOccurs="0" name="fullscreen" type="ob:bool"/> <xsd:element minOccurs="0" name="fullscreen" type="ob:bool"/>
<xsd:element minOccurs="0" name="maximized" type="ob:maximization"/> <xsd:element minOccurs="0" name="maximized" type="ob:maximization"/>
</xsd:all> </xsd:all>
<xsd:attribute name="role" type="xsd:string"/>
<xsd:attribute name="type" type="ob:clienttype"/>
<!-- at least one of these must be present --> <!-- at least one of these must be present -->
<xsd:attribute name="role" type="xsd:string"/>
<xsd:attribute name="title" type="xsd:string"/>
<xsd:attribute name="type" type="ob:clienttype"/>
<xsd:attribute name="name" type="xsd:string"/> <xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="class" type="xsd:string"/> <xsd:attribute name="class" type="xsd:string"/>
</xsd:complexType> </xsd:complexType>

View file

@ -192,6 +192,7 @@ void obt_prop_startup(void)
CREATE_(OB_CONTROL); CREATE_(OB_CONTROL);
CREATE_(OB_VERSION); CREATE_(OB_VERSION);
CREATE_(OB_APP_ROLE); CREATE_(OB_APP_ROLE);
CREATE_(OB_APP_TITLE);
CREATE_(OB_APP_NAME); CREATE_(OB_APP_NAME);
CREATE_(OB_APP_CLASS); CREATE_(OB_APP_CLASS);
CREATE_(OB_APP_TYPE); CREATE_(OB_APP_TYPE);

View file

@ -213,6 +213,7 @@ typedef enum {
OBT_PROP_OB_CONTROL, OBT_PROP_OB_CONTROL,
OBT_PROP_OB_VERSION, OBT_PROP_OB_VERSION,
OBT_PROP_OB_APP_ROLE, OBT_PROP_OB_APP_ROLE,
OBT_PROP_OB_APP_TITLE,
OBT_PROP_OB_APP_NAME, OBT_PROP_OB_APP_NAME,
OBT_PROP_OB_APP_CLASS, OBT_PROP_OB_APP_CLASS,
OBT_PROP_OB_APP_TYPE, OBT_PROP_OB_APP_TYPE,

View file

@ -236,7 +236,8 @@ void client_manage(Window window, ObPrompt *prompt)
ob_debug("Window type: %d", self->type); ob_debug("Window type: %d", self->type);
ob_debug("Window group: 0x%x", self->group?self->group->leader:0); ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
ob_debug("Window name: %s class: %s role: %s", self->name, self->class, self->role); ob_debug("Window name: %s class: %s role: %s title: %s",
self->name, self->class, self->role, self->title);
/* per-app settings override stuff from client_get_all, and return the /* per-app settings override stuff from client_get_all, and return the
settings for other uses too. the returned settings is a shallow copy, settings for other uses too. the returned settings is a shallow copy,
@ -796,7 +797,8 @@ static ObAppSettings *client_get_settings_state(ObClient *self)
gboolean match = TRUE; gboolean match = TRUE;
g_assert(app->name != NULL || app->class != NULL || g_assert(app->name != NULL || app->class != NULL ||
app->role != NULL || (signed)app->type >= 0); app->role != NULL || app->title != NULL ||
(signed)app->type >= 0);
if (app->name && if (app->name &&
!g_pattern_match(app->name, strlen(self->name), self->name, NULL)) !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
@ -809,6 +811,10 @@ static ObAppSettings *client_get_settings_state(ObClient *self)
!g_pattern_match(app->role, !g_pattern_match(app->role,
strlen(self->role), self->role, NULL)) strlen(self->role), self->role, NULL))
match = FALSE; match = FALSE;
else if (app->title &&
!g_pattern_match(app->title,
strlen(self->title), self->title, NULL))
match = FALSE;
else if ((signed)app->type >= 0 && app->type != self->type) { else if ((signed)app->type >= 0 && app->type != self->type) {
match = FALSE; match = FALSE;
} }
@ -1083,9 +1089,6 @@ static void client_get_all(ObClient *self, gboolean real)
from per-app settings */ from per-app settings */
client_get_session_ids(self); client_get_session_ids(self);
/* save the values of the variables used for app rule matching */
client_save_app_rule_values(self);
/* now we got everything that can affect the decorations */ /* now we got everything that can affect the decorations */
if (!real) if (!real)
return; return;
@ -1093,6 +1096,9 @@ static void client_get_all(ObClient *self, gboolean real)
/* get this early so we have it for debugging */ /* get this early so we have it for debugging */
client_update_title(self); client_update_title(self);
/* save the values of the variables used for app rule matching */
client_save_app_rule_values(self);
client_update_protocols(self); client_update_protocols(self);
client_update_wmhints(self); client_update_wmhints(self);
@ -2310,6 +2316,7 @@ static void client_save_app_rule_values(ObClient *self)
OBT_PROP_SETS(self->window, OB_APP_ROLE, utf8, self->role); OBT_PROP_SETS(self->window, OB_APP_ROLE, utf8, self->role);
OBT_PROP_SETS(self->window, OB_APP_NAME, utf8, self->name); OBT_PROP_SETS(self->window, OB_APP_NAME, utf8, self->name);
OBT_PROP_SETS(self->window, OB_APP_CLASS, utf8, self->class); OBT_PROP_SETS(self->window, OB_APP_CLASS, utf8, self->class);
OBT_PROP_SETS(self->window, OB_APP_TITLE, utf8, self->original_title);
switch (self->type) { switch (self->type) {
case OB_CLIENT_TYPE_NORMAL: case OB_CLIENT_TYPE_NORMAL:

View file

@ -200,8 +200,9 @@ static void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c)
static void parse_per_app_settings(xmlNodePtr node, gpointer d) static void parse_per_app_settings(xmlNodePtr node, gpointer d)
{ {
xmlNodePtr app = obt_xml_find_node(node->children, "application"); xmlNodePtr app = obt_xml_find_node(node->children, "application");
gchar *name = NULL, *class = NULL, *role = NULL, *type_str = NULL; gchar *name = NULL, *class = NULL, *role = NULL, *title = NULL,
gboolean name_set, class_set, type_set, role_set; *type_str = NULL;
gboolean name_set, class_set, type_set, role_set, title_set;
ObClientType type; ObClientType type;
gboolean x_pos_given; gboolean x_pos_given;
@ -212,6 +213,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d)
name_set = obt_xml_attr_string(app, "name", &name); name_set = obt_xml_attr_string(app, "name", &name);
type_set = obt_xml_attr_string(app, "type", &type_str); type_set = obt_xml_attr_string(app, "type", &type_str);
role_set = obt_xml_attr_string(app, "role", &role); role_set = obt_xml_attr_string(app, "role", &role);
title_set = obt_xml_attr_string(app, "title", &title);
/* validate the type tho */ /* validate the type tho */
if (type_set) { if (type_set) {
@ -235,7 +237,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d)
type_set = FALSE; /* not valid! */ type_set = FALSE; /* not valid! */
} }
if (class_set || name_set || role_set || type_set) { if (class_set || name_set || role_set || title_set || type_set) {
xmlNodePtr n, c; xmlNodePtr n, c;
ObAppSettings *settings = config_create_app_settings();; ObAppSettings *settings = config_create_app_settings();;
@ -248,6 +250,9 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d)
if (role_set) if (role_set)
settings->role = g_pattern_spec_new(role); settings->role = g_pattern_spec_new(role);
if (title_set)
settings->title = g_pattern_spec_new(title);
if (type_set) if (type_set)
settings->type = type; settings->type = type;
@ -352,7 +357,8 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d)
g_free(name); g_free(name);
g_free(class); g_free(class);
g_free(role); g_free(role);
name = class = role = NULL; g_free(title);
name = class = role = title = NULL;
} }
app = obt_xml_find_node(app->next, "application"); app = obt_xml_find_node(app->next, "application");
@ -1074,6 +1080,7 @@ void config_shutdown(void)
ObAppSettings *itd = (ObAppSettings *)it->data; ObAppSettings *itd = (ObAppSettings *)it->data;
if (itd->name) g_pattern_spec_free(itd->name); if (itd->name) g_pattern_spec_free(itd->name);
if (itd->role) g_pattern_spec_free(itd->role); if (itd->role) g_pattern_spec_free(itd->role);
if (itd->title) g_pattern_spec_free(itd->title);
if (itd->class) g_pattern_spec_free(itd->class); if (itd->class) g_pattern_spec_free(itd->class);
g_free(it->data); g_free(it->data);
} }

View file

@ -38,6 +38,7 @@ struct _ObAppSettings
GPatternSpec *class; GPatternSpec *class;
GPatternSpec *name; GPatternSpec *name;
GPatternSpec *role; GPatternSpec *role;
GPatternSpec *title;
ObClientType type; ObClientType type;
GravityPoint position; GravityPoint position;

View file

@ -297,6 +297,7 @@ gboolean screen_annex(void)
supported[i++] = OBT_PROP_ATOM(OB_CONTROL); supported[i++] = OBT_PROP_ATOM(OB_CONTROL);
supported[i++] = OBT_PROP_ATOM(OB_VERSION); supported[i++] = OBT_PROP_ATOM(OB_VERSION);
supported[i++] = OBT_PROP_ATOM(OB_APP_ROLE); supported[i++] = OBT_PROP_ATOM(OB_APP_ROLE);
supported[i++] = OBT_PROP_ATOM(OB_APP_TITLE);
supported[i++] = OBT_PROP_ATOM(OB_APP_NAME); supported[i++] = OBT_PROP_ATOM(OB_APP_NAME);
supported[i++] = OBT_PROP_ATOM(OB_APP_CLASS); supported[i++] = OBT_PROP_ATOM(OB_APP_CLASS);
supported[i++] = OBT_PROP_ATOM(OB_APP_TYPE); supported[i++] = OBT_PROP_ATOM(OB_APP_TYPE);