You are not logged in.

#1 2017-06-25 00:19:34

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

i3 have border show up and disappear for couple of milliseconds

I am using i3-gaps and I wanted to attempt to do a little aesthetic thing to my setup.
What I am trying to do is that whenever you focus on a new window in i3, a border will show up and disappear for a couple of seconds.

I was able to achieve that here using i3ipc-python (Code: http://termbin.com/rn8c):
https://s4.postimg.org/sggvem4il/i3ipc_Bopping.gif
But... You can notice that the window resizes every time the border is added and doesn't look as clean...

So I my second attempt to this was to actually instead have the border always there and just have the color change... But... I asked the i3 people on github and they say that they do not have a way to do change border color dynamically nor they are thinking of adding such a solution.

So I thought of an even hackier solution, manually write to the i3 config file and then use i3-msg reload to apply the affects, in theory it would work but... I don't know how to make the border transparent...
https://s22.postimg.org/dh0muomtd/Scree … -18-58.png
I can't find any documentation on borders that are transparent (I tried using a 4 byte hex color, that didn't work) so I was wondering on how to make a border transparent.

Thanks for any help!

-- mod edit: converted img to url tags.  Trilby --

Last edited by Trilby (2017-06-25 00:22:00)

Offline

#2 2017-06-25 00:24:07

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

Re: i3 have border show up and disappear for couple of milliseconds

You've been told previously about our image size restrictions and even apolgized (confirming you saw the warning).  Then in your very next two threads within days of the warning you again post oversized images.

It's a simple rule.  Follow it.

As for your question - I'm not familiar with the tool you used to get the partially working solution, can it also move/resize a window?  The window position should be incremented by the border with and the size decremented by two times the border width when the border is showing.

Alternatively, if you can patch the i3 code, changing a window border color in Xlib is ridiculously easy - so much so that I think the i3 people must have just been blowing you off as they didn't want to help with it.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-06-25 00:25:17

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

Sorry, about that... I overlooked that rule again...

Offline

#4 2017-06-25 00:29:30

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

Re: i3 have border show up and disappear for couple of milliseconds

No worries.  Please see my edit for some input on your problem.  You see to work at your own problems and contribute solutions - so you're someone we'd probably want active on these forums, so just get used to our posting guidelines smile


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-06-26 17:36:44

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

I think I have to clear up how my partially working solution works...
In my first attempt I used i3ipc-python, which is an adaptation if the i3ipc in a python format that I guess you could say enables me to do some "advanced" i3 stuff.

I just realized that you can't see my code (termbin has been acting up a lot lately...) so here it is:

#!/bin/bash python

import i3ipc
import time

i3 = i3ipc.Connection()

def borderfocus(i3, event):
	i3.command("border pixel 2")
	time.sleep(0.25)
	i3.command("border pixel 0")
	time.sleep(0.25)

i3.on("window::focus", borderfocus)
i3.main()

You can see that every time that there is a new focused window (i3.on("window::focus", borderfocus)), it will run the above borderfocus function, using this method is fast and enables me to listen to i3 events really easily.
But you can see that this method has me spawn a new border and then quickly making it dissappear (i3.command("border pixel 2") this is equivalent to i3-msg border pixel 2)
It works, but as you can see in my gif that every time that border comes up and disappears that the window has to resize to accommodate the space of the border.

So my second idea was to still use the ipc but instead of having the border disappearing and reappearing, instead of the color change instead, but again as I said the i3 people are not implementing a way to dynamically change border color (you have to go to your config and change colors there as stated in the documentation: https://i3wm.org/docs/userguide.html#_changing_colors)... Which also begs the question of how do I make a transparent border?

My third attempt still had the principles of my second attempt (change the color the border), but instead change the actual i3 config and then reload it to have the new color of the border take into affect. (This is where I realized that I did not know how to make a transparent border)

So what is this Xlib that you talk of and how can I use it to change the border color?

Last edited by Hacksaurus_Babu (2017-06-26 17:40:57)

Offline

#6 2017-06-26 17:49:24

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

Re: i3 have border show up and disappear for couple of milliseconds

Ah, I didn't know you we're just using i3 commands - I'm not familiar with i3.  There are commands to move and resize windows (or "containers") - so you could just use your current approach to set the border width to 2, move the container +2 +2 and resize the container -4 -4 sleep, then undo those changes.

Xlib is a library implementing the X11 protocol and is most likely what i3 uses (although they may use xcb, but xcb has equivalent functions).

You could potentially do this with your own program listening to the X11 events directly:

// compile with:  gcc -o focus_flash focus_flash.c -lX11

#include <unistd.h>
#include <X11/Xlib.h>

int main(int argc, const char **argv) {
	Display *dpy = XOpenDisplay(0x0);
	XSelectInput(dpy, DefaultRootWindow(dpy), FocusChangeMask);
	XEvent ev;
	Window win;
	int ignore;
	while (!XNextEvent(dpy,&ev)) {
		if (ev.type != FocusIn) continue;
		XFlush(dpy);
		XGetInputFocus(dpy, &win, &ignore);
		XSetWindowBorder(dpy, win, 0xFFDD0E);
		XFlush(dpy);
		usleep(400000);
		XSetWindowBorder(dpy, win, 0x000000);
	}
	return 0;
}

The above is only minimally tested.  When compiled and run, it listens for FocusIn events and turns the focused windows border yellow (FFDD0E) for 400ms then returns it to black (000000).  This does not change the border width, but that would be fairly straitforward to add if you wanted.

This should work when any keybinding is used to change the focused window.  It may or may not work as-is with focus-follows-mouse set ups, but this would be pretty easy to get working to if needed.

I'm not very good with python, but there are xlib bindings for python if you wanted to make your own version that you could work with.  The following seems to be a related example in python, though it looks overcomplicated to me:
https://gist.github.com/ssokolow/e7c9aa … f969a78ae8


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2017-06-26 20:13:49

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

When googling "i3 resize container", this thing came up: https://www.reddit.com/r/i3wm/comments/ … ackground/
Apparently they are saying that if I get the i3-gaps-next-git package I should be able to use transparent borders... But its seems to be a very unstable release of i3-gaps...
Screenshot_2017-06-26_13-10-39.png
Heh this is a smaller than 250px, you can't warn me this time

I'll try to figure out how your solution works (I don't know that much about C), I'll notify you if I need help!

EDIT:
Apparently the transparency part only applies to i3bar...

Last edited by Hacksaurus_Babu (2017-06-26 21:00:49)

Offline

#8 2017-06-29 18:41:32

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

Sorry for the long delay, but I was working something else for the time being, but I was wondering if you could sort of breakdown your code where it spawns the border?
Thank you!

Offline

#9 2017-06-29 21:51:09

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

Re: i3 have border show up and disappear for couple of milliseconds

The code as it is doesn't change the border width - so this would just be fore flashing an existing border.  If you change the border width, you'd also need to change the winow size and position, and unfortunately Xlib doesn't have a relative move/resize function, so you'd have to first query the window size.  The following will just adjust the border width to 2 pixes then return it to what it was before.  If you just set the default border color to the intended flash color, this will be all you need.  But I've left the commented lines in there that you can uncomment if you also need to be able to change the border color at the same time (a border can have a color and 0 width - so you'd not see the color until the width was set to be larger).

// compile with:  gcc -o focus_flash focus_flash.c -lX11

#include <unistd.h>
#include <X11/Xlib.h>

#define BW   2

int main(int argc, const char **argv) {
   Display *dpy = XOpenDisplay(0x0);
   XSelectInput(dpy, DefaultRootWindow(dpy), FocusChangeMask);
   XEvent ev;
   Window win, wig;
   int ig, x, y;
   unsigned int w, h, bw;
   while (!XNextEvent(dpy,&ev)) {
      if (ev.type != FocusIn) continue;
      XFlush(dpy);
      XGetInputFocus(dpy, &win, &ig);
      XGetGeometry(dpy, win, &wig, &x, &y, &w, &h, &bw, &ig);
      //XSetWindowBorder(dpy, win, 0xFFDD0E);
      if (bw < BW) {
         XSetWindowBorderWidth(dpy, win, BW);
         XMoveResizeWinow(dpy, win, x - BW, y - BW, w + 2 * BW, h + 2 * BW);
      }
      XFlush(dpy);
      usleep(400000);
      XSetWindowBorderWidth(dpy, win, bw);
      XMoveResizeWinow(dpy, win, x, y, w, h);
      //XSetWindowBorder(dpy, win, 0x000000);
   }
   return 0;
}

Also note that this adds an "outer" border to the window which allows the window content to remain unchanged.  But if you don't have gaps between windows/containers, this would not work well (in your gif, you do have gaps).  This could also be adjusted to add an "inner" border so the extents of the window remain the same, but the content of the window would be made slightly smaller during the 'flash' which could occasionally look quite odd as the client may redraw the content differently (e.g., text in a terminal might wrap differntly).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2017-06-29 21:56:19

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

Hmm... Nothing seems to be coming up, and me not understand C is not sort of hindering me understanding on what is happening here... Is it possible to show me a gif to give me a better understanding on what the results should be?

Offline

#11 2017-06-29 22:15:09

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

Re: i3 have border show up and disappear for couple of milliseconds

I don't have i3, or any WM that you'd recognize - so I can't really.  But it is possible for a window manager to override changes to border width and window size/position - especially a tiler like i3.  It's much less likely that a WM would interfer with setting a border color of an already existing border, which is why the first code example is more likely to work.

But I also suspect you must not be using the code properly.  Are you compiling and running it, or what are you doing with the code?  I only realized after your comment that there is a typo in my second code block which would not even compile.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2017-06-29 23:26:25

Hacksaurus_Babu
Member
Registered: 2017-01-21
Posts: 106

Re: i3 have border show up and disappear for couple of milliseconds

I actually did notice the typos your program... You spelled "Window" as "Winow" twice. but I compiled it using the gcc -o focus_flash focus_flash.c -lX11 command and then ran it ./focus_flash... I'm pretty sure that I am using the program correctly...

Offline

Board footer

Powered by FluxBB