Introduce support for specifying variables from X resources. (#2286)
This patch introduces a new 'set_from_resource' config directive which allows defining a variable by retrieving its value from the X resource database. This avoids having to configure a color scheme in multiple files. The directive takes an additional fallback value which is used in case the resource cannot be found or during config validation where no X connection is available. Furthermore, this patch includes the following changes: - If the same variable is defined twice, we now properly overwrite the value of the assignment rather than inserting two variable definitions with the same key. - We now depend on xcb-util-xrm to query the resource. - Increase the buffer size for variable / resource assignments. fixes #2130
This commit is contained in:
committed by
Michael Stapelberg
parent
dbafb3cf23
commit
47562b4143
@ -441,7 +441,7 @@ client.focused #4c7899 #285577 #ffffff #2e9ef4
|
||||
EOT
|
||||
|
||||
my $expected_all_tokens = <<'EOT';
|
||||
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'no_focus', 'focus_follows_mouse', 'mouse_warping', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'focus_on_window_activation', 'show_marks', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent', 'client.placeholder'
|
||||
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'set_from_resource', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'no_focus', 'focus_follows_mouse', 'mouse_warping', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'focus_on_window_activation', 'show_marks', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent', 'client.placeholder'
|
||||
EOT
|
||||
|
||||
my $expected_end = <<'EOT';
|
||||
|
64
testcases/t/532-xresources.t
Normal file
64
testcases/t/532-xresources.t
Normal file
@ -0,0 +1,64 @@
|
||||
#!perl
|
||||
# vim:ts=4:sw=4:expandtab
|
||||
#
|
||||
# Please read the following documents before working on tests:
|
||||
# • http://build.i3wm.org/docs/testsuite.html
|
||||
# (or docs/testsuite)
|
||||
#
|
||||
# • http://build.i3wm.org/docs/lib-i3test.html
|
||||
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
||||
#
|
||||
# • http://build.i3wm.org/docs/ipc.html
|
||||
# (or docs/ipc)
|
||||
#
|
||||
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
||||
# (unless you are already familiar with Perl)
|
||||
#
|
||||
# Tests for using X resources in the config.
|
||||
# Ticket: #2130
|
||||
use i3test i3_autostart => 0;
|
||||
use X11::XCB qw(PROP_MODE_REPLACE);
|
||||
|
||||
sub get_marks {
|
||||
return i3(get_socket_path())->get_marks->recv;
|
||||
}
|
||||
|
||||
my $config = <<EOT;
|
||||
# i3 config file (v4)
|
||||
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
||||
|
||||
# This isn't necessarily what X resources are intended for, but it'll do the
|
||||
# job for the test.
|
||||
set_from_resource \$mark i3wm.mark none
|
||||
for_window [class=worksforme] mark \$mark
|
||||
|
||||
set_from_resource \$othermark i3wm.doesnotexist none
|
||||
for_window [class=doesnotworkforme] mark \$othermark
|
||||
|
||||
EOT
|
||||
|
||||
$x->change_property(
|
||||
PROP_MODE_REPLACE,
|
||||
$x->get_root_window(),
|
||||
$x->atom(name => 'RESOURCE_MANAGER')->id,
|
||||
$x->atom(name => 'STRING')->id,
|
||||
32,
|
||||
length('*mark: works'),
|
||||
'*mark: works');
|
||||
$x->flush;
|
||||
|
||||
my $pid = launch_with_config($config);
|
||||
|
||||
open_window(wm_class => 'worksforme');
|
||||
sync_with_i3;
|
||||
is_deeply(get_marks(), [ 'works' ], 'the resource has loaded correctly');
|
||||
|
||||
cmd 'kill';
|
||||
|
||||
open_window(wm_class => 'doesnotworkforme');
|
||||
sync_with_i3;
|
||||
is_deeply(get_marks(), [ 'none' ], 'the resource fallback was used');
|
||||
|
||||
exit_gracefully($pid);
|
||||
|
||||
done_testing;
|
Reference in New Issue
Block a user