Re: [i3] tray_output for primary display

  • From: José Luis Pereira <onaips@xxxxxxxxx>
  • To: "Discussions/Questions about the i3 window manager" <i3-discuss@xxxxxxxxxxxxx>
  • Date: Wed, 21 Mar 2012 09:22:53 +0000

Here you have, packed a doc, removed whitespace and changed if order.

Best Regards

------
José Pereira


On Wed, Mar 21, 2012 at 12:36 AM, Fernando Lemos <fernandotcl@xxxxxxxx>wrote:

Hi,

2012/3/20 José Luis Pereira <onaips@xxxxxxxxx>:
Dear Michael, All

Here you have the patch that implements the "primary" output feature. Its
working fairly well, could you add it also in the docs?
Also, user should be aware that the is no default primary display (at
least
in my debian machine), you can make it by doing so:
xrandr --output <output_display> --primary

Looks good, though I didn't test it. Some very minor suggestions, feel
free to ignore them to your discretion:

* I'd prefer to do the boolean comparison first in the "if" clause.
There's no performance improvement in practice, but it seems more
correct to me.

* You've added a trailing whitespace to i3bar/outputs.h.

If you can, please submit a patch for the docs. They're in the same
Git repository. I believe you may choose to use send a different
patch, or simply pack the changes in the same commit (specially as the
changes should be simple enough).

Regards,

diff --git a/docs/userguide b/docs/userguide
index e75f1ca..69eaa29 100644
--- a/docs/userguide
+++ b/docs/userguide
@@ -896,7 +896,7 @@ you can turn off the functionality entirely.

*Syntax*:
-------------------------
-tray_output <none|output>
+tray_output <none|primary|output>
-------------------------

*Example*:
@@ -904,10 +904,18 @@ tray_output <none|output>
# disable system tray
tray_output none

+# show tray icons on the primary monitor
+tray_output primary
+
# show tray icons on the big monitor
tray_output HDMI2
-------------------------

+Note that you might not have a primary output configured yet. To do so, run:
+-------------------------
+xrandr --output <output> --primary
+-------------------------
+
=== Font

Specifies the font (again, X core font, not Xft, just like in i3) to be used in
diff --git a/i3bar/include/outputs.h b/i3bar/include/outputs.h
index 6501c31..f9ddd54 100644
--- a/i3bar/include/outputs.h
+++ b/i3bar/include/outputs.h
@@ -40,6 +40,7 @@ i3_output* get_output_by_name(char* name);
struct i3_output {
char* name; /* Name of the output */
bool active; /* If the output is active */
+ bool primary; /* If it is the primary output */
int ws; /* The number of the currently visible ws */
rect rect; /* The rect (relative to the root-win) */

diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c
index 9dc5cab..83a4c24 100644
--- a/i3bar/src/outputs.c
+++ b/i3bar/src/outputs.c
@@ -45,15 +45,19 @@ static int outputs_null_cb(void *params_) {
static int outputs_boolean_cb(void *params_, int val) {
struct outputs_json_params *params = (struct outputs_json_params*) params_;

- if (strcmp(params->cur_key, "active")) {
- return 0;
+ if (!strcmp(params->cur_key, "active")) {
+ params->outputs_walk->active = val;
+ FREE(params->cur_key);
+ return 1;
}

- params->outputs_walk->active = val;
-
- FREE(params->cur_key);
+ if (!strcmp(params->cur_key, "primary")) {
+ params->outputs_walk->primary = val;
+ FREE(params->cur_key);
+ return 1;
+ }

- return 1;
+ return 0;
}

/*
diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c
index afcfaa3..b4df8cd 100644
--- a/i3bar/src/xcb.c
+++ b/i3bar/src/xcb.c
@@ -453,9 +453,12 @@ static void
handle_client_message(xcb_client_message_event_t* event) {
SLIST_FOREACH(walk, outputs, slist) {
if (!walk->active)
continue;
- if (config.tray_output &&
- strcasecmp(walk->name, config.tray_output) != 0)
- continue;
+ if (config.tray_output) {
+ if ((strcasecmp(walk->name, config.tray_output) != 0) &&
+ (!walk->primary || strcasecmp("primary",
config.tray_output) != 0))
+ continue;
+ }
+
DLOG("using output %s\n", walk->name);
output = walk;
}
diff --git a/src/ipc.c b/src/ipc.c
index fe1464e..60533da 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -408,6 +408,9 @@ IPC_HANDLER(get_outputs) {
ystr("active");
y(bool, output->active);

+ ystr("primary");
+ y(bool, output->primary);
+
ystr("rect");
y(map_open);
ystr("x");

Other related posts: