Merge pull request #2970 from CyberShadow/i3bar-primary-output

Do not canonicalize special output names
This commit is contained in:
Michael Stapelberg 2017-09-19 18:57:55 +02:00 committed by GitHub
commit 919e66399b
3 changed files with 60 additions and 8 deletions

View File

@ -28,17 +28,27 @@ static Output *get_screen_at(unsigned int x, unsigned int y) {
/*
* Creates outputs according to the given specification.
* The specification must be in the format wxh+x+y, for example 1024x768+0+0,
* optionally followed by 'P' to indicate a primary output,
* with multiple outputs separated by commas:
* 1900x1200+0+0,1280x1024+1900+0
* 1900x1200+0+0P,1280x1024+1900+0
*
*/
void fake_outputs_init(const char *output_spec) {
char useless_buffer[1024];
const char *walk = output_spec;
unsigned int x, y, width, height;
while (sscanf(walk, "%ux%u+%u+%u", &width, &height, &x, &y) == 4) {
DLOG("Parsed output as width = %u, height = %u at (%u, %u)\n",
width, height, x, y);
int chars_consumed;
while (sscanf(walk, "%ux%u+%u+%u%n", &width, &height, &x, &y, &chars_consumed) == 4) {
walk += chars_consumed;
bool primary = false;
if (*walk == 'P') {
primary = true;
walk++;
}
if (*walk == ',')
walk++; /* Skip delimiter */
DLOG("Parsed output as width = %u, height = %u at (%u, %u)%s\n",
width, height, x, y, primary ? " (primary)" : "");
Output *new_output = get_screen_at(x, y);
if (new_output != NULL) {
DLOG("Re-used old output %p\n", new_output);
@ -67,9 +77,7 @@ void fake_outputs_init(const char *output_spec) {
init_ws_for_output(new_output, output_get_content(new_output->con));
num_screens++;
}
/* Figure out how long the input was to skip it */
walk += sprintf(useless_buffer, "%ux%u+%u+%u", width, height, x, y) + 1;
new_output->primary = primary;
}
if (num_screens == 0) {

View File

@ -580,6 +580,10 @@ static void dump_bar_bindings(yajl_gen gen, Barconfig *config) {
}
static char *canonicalize_output_name(char *name) {
/* Do not canonicalize special output names. */
if (strcasecmp(name, "primary") == 0) {
return name;
}
Output *output = get_output_by_name(name, false);
return output ? output_primary_name(output) : name;
}

View File

@ -0,0 +1,40 @@
#!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 that i3bars configured to use the primary output do not have
# their output names canonicalized to something other than "primary".
# Ticket: #2948
# Bug still in: 4.14-93-ga3a7d04a
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
fake-outputs 1024x768+0+0P
bar {
output primary
}
EOT
my $bars = i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');
my $bar_id = shift @$bars;
my $bar_config = i3->get_bar_config($bar_id)->recv;
is_deeply($bar_config->{outputs}, [ "primary" ], 'bar_config output is primary');
done_testing;