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: Tue, 20 Mar 2012 08:38:10 +0000

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


Looking forward to contribute with more patches.
Best Regards
------
José Pereira

On Sun, Mar 18, 2012 at 5:09 PM, Michael Stapelberg <michael@xxxxxxxx>wrote:

Hi José,

Excerpts from José Luis Pereira's message of 2012-03-18 14:34:43 +0100:
Thanks for your anwer. I would like to implement the feature, i have
fairly
Awesome!

good C knowledge for this. Would you give me some guidelines?
I have been looking into the code and i found out that the modification
should be in xbc.c on i3bar source, am i right?
Yes, partly:

Since i3bar uses IPC and doesn’t query RandR directly, I recommend
introducing
a new boolean member in the IPC reply for the get_outputs message (see
i3-msg
-t get_outputs), called "primary". Then, make i3bar handle "primary" as a
special value (case-insensitively) in i3bar/src/xcb.c.

Feel free to send patches to this mailing list for review and feel free to
drop
by on IRC to clarify any questions you might have.

Best regards,
Michael

diff --git a/i3bar/include/outputs.h b/i3bar/include/outputs.h
index 6501c31..cb336be 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 29ffe1c..3615603 100644
--- a/i3bar/src/xcb.c
+++ b/i3bar/src/xcb.c
@@ -452,9 +452,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) &&
+ (strcasecmp("primary", config.tray_output) != 0 ||
!walk->primary))
+ 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: