You are not logged in.

#1 2016-12-31 12:56:40

areuz
Member
Registered: 2016-09-16
Posts: 60

[Solved] How to bind a key to rotate the currently focused screen

I'm trying to use only one key in my i3-wm config to rotate the currently focused monitor - basically the on that the focused window is on.
But if I want to do

 $ Xrandr --rotate left 

then it requires me to specify a '--output' device (for me either DP-3 or DP-5) - which I do not know how to get.

One more thing to note, is that I have each Workspace assigned to a specific output, if it helps:

workspace $Ws1 output DP-5
workspace $Ws2 output DP-3
workspace $Ws3 output DP-5
workspace $Ws4 output DP-3
workspace $Ws5 output DP-5
workspace $Ws6 output DP-3
workspace $Ws7 output DP-5
workspace $Ws8 output DP-3
workspace $Ws9 output DP-5

Thanks in advance!

Last edited by areuz (2016-12-31 14:41:18)


If I'm not a bush, I'm not no one.
Dotfiles Git

Offline

#2 2016-12-31 14:05:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: [Solved] How to bind a key to rotate the currently focused screen

The only way to go from a focused window to the output it's on is by coordinates.  You can get the coordinates of the window with something like wmctrl - and xrandr will give you the coordinates and size of each output.

The following would do this in C - with no parameters, this will just return the name of the output the currently focused window is on.  With any parameters it will instead give the output that the mouse is currently in:

/*
WHICHOUT.C
Released to public domain
gcc -o whichout whichout.c -lX11 -lXrandr
*/

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>

int main(int argc, const char *const *argv) {
   int i, tx = 0, ty = 0;
   Display *dpy = XOpenDisplay(0x0);
   Window root = DefaultRootWindow(dpy);
   Window wig, win;
   XGetInputFocus(dpy, &win, &i);
   if (argc == 1) XGetGeometry(dpy, win, &wig, &tx, &ty, &i, &i, &i, &i);
   else XQueryPointer(dpy, win, &wig, &wig, &tx, &ty, &i, &i, &i);
   if (!dpy) return 1;
   XRRScreenResources *res = XRRGetScreenResources(dpy, root);
   if (!res) return 2;
   for (i = 0; i < res->noutput; ++i) {
      XRROutputInfo *info = XRRGetOutputInfo(dpy, res, res->outputs[i]);
      if (!info || !info->crtc) continue;
      XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy,res,info->crtc);
      if (!crtc) { XRRFreeOutputInfo(info); continue; }
      if (!(tx < crtc->x || tx > crtc->x + crtc->width || ty < crtc->y || ty > crtc->y + crtc->height)) {
         printf(info->name);
         break;
      }
      XRRFreeCrtcInfo(crtc);
      XRRFreeOutputInfo(info);
   }
   XRRFreeScreenResources(res);
   XCloseDisplay(dpy);
   return 0;
}

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2016-12-31 14:38:52

areuz
Member
Registered: 2016-09-16
Posts: 60

Re: [Solved] How to bind a key to rotate the currently focused screen

Thanks Trilby! I hoped that there was another easier way by now, I saw a similar post from like 2 years ago. But I guess there is no way around that.


If I'm not a bush, I'm not no one.
Dotfiles Git

Offline

#4 2016-12-31 14:40:45

areuz
Member
Registered: 2016-09-16
Posts: 60

Re: [Solved] How to bind a key to rotate the currently focused screen

Also, this another reason is why I don't like the 'add [Solved] in the title' approach combined with the title length restrictions. I have to shorten my title now...


If I'm not a bush, I'm not no one.
Dotfiles Git

Offline

#5 2016-12-31 14:49:31

areuz
Member
Registered: 2016-09-16
Posts: 60

Re: [Solved] How to bind a key to rotate the currently focused screen

Hm.. It works very strangely with multiple workspaces, I will have to figure out how it works first.

Actually (sorry for 3 posts in a row xD) I just found a tool called 'xdotool' - which when used like

xdotool get_dekstop

returns an int of 0 - n_screens, which in my case will work perfectly for a simple bash 'case' statement!

I'll post the code in few, and I'll try to make it inline wink

Last edited by areuz (2016-12-31 14:52:44)


If I'm not a bush, I'm not no one.
Dotfiles Git

Offline

Board footer

Powered by FluxBB