AB9IL.net

i3wm: Using i3-ipc to Float Windows

Disclosure: AB9IL.net is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program such that this site earns advertising fees by linking to Amazon.com. If you make a qualifying purchase after clicking a link on this website, the associate affiliated with this site may earn a comission at no cost to you.


#Advert: Fabulous software deserves a fabulous machine from CyberpowerPC.

New Features: Global Quick Tune Internet SDR List Improve Your Radio Knowledge at "YouTube SDR School"
Article Index --- click here to unfold ---
Newest Pages NEW: Trumpists Kicking the Hornets Nest
NEW: Introduction to Catbird Linux
NEW: Skywave Linux Updated to ver 4.1
NEW: i3wm: Using i3-ipc to Float Windows
How to Record from WebSDR and OpenWebRX Sites
Programmatic RTL-SDR Frequency Claibration
Public KiwiSDR Lists
Malaysia Airlines Flight MH17: Simply Mass Murder
The Anonymous Cathay Pacific Employee Letter to Hong Kong
For For Cathay Crews Crossing Borders With Electronics
Photo Gallery 9: The New Life Movement in China, 1944
E Pluribus Unum: From Many, One, Dammit
HFGCS Quick Tune SDR List
The Robert Mueller Iron Triangle Speech
A Rant About One Party Rule
Best OpenWebRX and WebSDR Servers
SDR School via YouTube
ADALM-PlutoSDR on Linux Systems
MOFO Linux: Defeating State Censorship and Surveillance
Linux: Distros, Code, and Nifty Software NEW: Introduction to Catbird Linux
NEW: Skywave Linux Updated to ver 4.1
NEW: i3wm: Using i3-ipc to Float Windows
Skywave Linux: HPSDR, WebSDR, and RTL-SDR ready to run.
Siduction Linux with the Cinnamon Desktop
Siduction Linux with the LXQT Desktop
Andy's Ham Radio Linux 15 and QtRadio
Booting Multiple Linux Disc Images with Grub2
Porteus Linux Hard Drive Installation
UPDATED: MOFO Linux - For Unrestricted Internet
Aptosid with LXDE
Asus EeePC 1215N with Linux
Autostart Tweaks for KDE3 and KDE4
Broadband Speed Tweaks For Linux
Fixing the Firefox 3 Rendering Bug
Linux on Solid State Drives
Linux Wireless Interface Driver Updates
Setting Polkit to Automount USB Devices
Sidux with LXDE
Fixing Skype Inverted Video
SLAX Remix - kernel upgrades
Flash Drive Linux - Introduction
Flash Drive Knoppix 5.3 - Part 1
Flash Drive Knoppix 5.3 - Part 2
Flash Drive Knoppix 6.0 - Part 1
Flash Drive Knoppix 6.0 - Part 2
Flash Drive SLAX - Part 1
Flash Drive SLAX - Part 2
Flash Drive Bluewhite64 - Part 1
Flash Drive Bluewhite64 - Part 2
Flash Drive Linux - Basic Customization
SLAX Customization - Part 1
SLAX Customization - Part 2
Bluewhite64 Customization - Part 1
Bluewhite64 Customization - Part 2
Long Range Wi-Fi Basics of Long Range Wireless Networking
Linear Focus Parabolic Wi Fi Antenna
High Gain Wi Fi Dish Antenna
High Gain Helical Wi Fi Antenna
High Gain Yagi Wi Fi Antenna
High Power Wireless Adapters
Wi Fi Extender Antenna for Routers
Belkin F5D7050 External Wi Fi Antenna
Linksys WUSB54GC External Antenna Mod
Compat Wireless Linux Drivers
Installing WPA_Supplicant for Wi-Fi Security
Linux Wireless Interface Driver Updates
Linux Wireless Interface Driver Support
NetworkManager and Consolekit
RT73 Wireless Drivers for Linux Kernel 2.6.27+
RT2860 Wireless Drivers for Linux Kernel 2.6.27+
Radio: Amateur Radio, Aero Radio, Shortwave, etc NEW: Programmatic RTL-SDR Frequency Claibration
NEW: Public KiwiSDR Lists
NEW: GHFS Quick Tune SDR List
UPDATED: Best OpenWebRX and WebSDR Servers
UPDATED: Skywave Linux: HPSDR, WebSDR, and RTL-SDR ready to run.
CubicSDR on Debian, Ubuntu, and Linux Mint
Dump1090 for Linux Mint 17.1 and Siduction 2014.1
Software Defined Radio - An Introduction
QS1R Direct Sampling SDR
Chaining SDR Audio Interfaces
FLEX-6000 Direct Sampling SDR
UPDATED: RTL2832 Software Defined Radio
WebSDR Digimode Reception
Enabling FLASH in Jack Audio
Realtime Software Audio Processing
Liberation Technology MOFO Linux - For Unrestricted Internet
Veracrypt Encryption for Linux
Veracrypt Encryption for Windows
Using Google Within China
Popcorn Time and Flixtor for Uncensored Streaming Media
DNS Encryption using DNSCrypt
Galaxy Nexus Privacy and Robustness Enhancements
Galaxy SIII Privacy and Robustness Enhancements
Flash Drive Encryption for Linux
Flash Drive Encryption for Windows
Multihop VPN Connections for Strong Internet Privacy
Open and Free DNS Server List
OpenVPN Cloaking against Deep Packet Inspection The Serval Mesh Phone Project
Skype's Robust Security
Man in the Middle Wireless Security Risks
Wireless Security and Surveillance
Digital Audio Adjusting Audio Dynamics in VLC
Backing Track Prep Guide
Ipod Music Processing Guide
How To Record Record Live Music Performances
Realtime Software Audio Processing
Chaining SDR Audio Interfaces
Aerospace Radio, Aviation, Pontification, and Opinion NEW: Trumpists Kicking the Hornets Nest
NEW: The Anonymous Cathay Pacific Employee Letter to Hong Kong
NEW: For For Cathay Crews Crossing Borders With Electronics
NEW: E Pluribus Unum: From Many, One, Dammit
NEW: HFGCS Quick Tune SDR List
NEW: The Robert Mueller Iron Triangle Speech
NEW: A Rant About One Party Rule
Captains Authority Versus Autocratic Airline Management
Malaysia Airlines Flight MH17: Simply Mass Murder
Malaysia Airlines Flight MH370 - A Media Circus
High Gain Air Band Antennas
Apollo Unified S Band Communications
Chinese Anti-Stealth VHF Radar
Oceanic Communications - Procedures, Equipment, Voice and HFDL
Boeing 737NG Radio Equipment
Boeing 767 Radio Equipment
NAOC-TACAMO Monitoring
My Flight on 9/11
Joshua Chamberlain's Leadership Tips
Special Operations Forces Truths
TWA 800: Just Give Me Some Truth
Photo Gallery Aviation Photo Gallery 1: Snapshots From My Journeys
Aviation Photo Gallery 2: On the Road With ATA Airlines
Aviation Photo Gallery 3: More ATA Airlines
Aviation Photo Gallery 4: Southwest Airlines is the Borg Empire
Aviation Photo Gallery 5: Starting Over, Moving On...
Aviation Photo Gallery 6: More Viva Macau
Aviation Photo Gallery 7: Mainland China Airline Flying
Aviation Photo Gallery 8: Chinese Smog and Fog
NEW: Photo Gallery 9: The New Life Movement in China, 1944
Broadcasting BBC Radio Blooper - Adolf Merckle
TV DXing the World Trade Center
New York TV after 9/11
Live Music Recording Adjusting Audio Dynamics in VLC
Backing Track Prep Guide
Ipod Music Processing Guide
How To Record Record Live Music Performances
Radio Poetry and Arts In Distress, by David Wagoner
Just A Radio Operator, by Robert A. Wallace
Radio Circuit Modifications ATS-909 Modifications
ATS-909 Manuals
ATS-909 Alignment Procedure
ATS-909 Alignment Spectrograms
Very Low Frequency (VLF) Radio Internet Based VLF Radio Listening
Windows Tips Windows Performance Enhancement Tips
A Faster Windows 7
Windows 7 SSD Setup

Budlabs showing how to float windows by
using an i3 ipc listener script.

My coding of an i3 ipc listener which automatically
scales floating windows in proportion to screen
resolution.

Recently, I have been tweaking the i3 configuration in my machines, seeking to reduce latency and achieve smoother operation. The defaults and conventional setup are fine (no problems), but my intention is to rice the system and do numerous little things which can add latency reveal quirks in an otherwise smooth and fast window manager. Let us look into the issue as it relates to opening some specific applications in floating windows while other applications open in the tabbed or tiled layout.

It is the i3 config file which is used by most people to set the default layout options and any settings which differ for specific applications. For example, my preference is for terminals, web and file browsers, and certain utilities to open floating above the other tiled windows. To open certain windows in floating mode, the config file would have lines like this:



for_window [class="gnome-terminal"] floating enable
for_window [class="URxvt"] floating enable

Budlabs posted a Youtube video describing a phenomenon where a visible glitch occurs when a new window is opened or if the title or class changes. What happens is that i3 begins to make the changes associated with the new window or changed title, but takes a number of milliseconds to read all of the the for_window rules in the config file. Those rules are searched to determine if there is one applicable to the window being opened or changed. What can be done to eliminate the glitch?

#Advert: Unleash your powers with a Razer laptop.

Budlabs crafted a clever solution in which the for_window rules are replaced with a short bit of code in a separate script, using interprocess communication. This means it is necessary to run an i3-ipc process to monitor what i3 is doing and intervene with a command to handle the opening of a new window. The solution is fast, efficient, and smooth. Any of the available ipc listeners may be used to recognize the time when a new window is being opened. Then, I use a Python script similar to what Budlabs uses, but with changes to limit floating mode to specific windows.

Mister Bud used the following code, within a listener script, to find window opening events:

i3.on('window::new', set_floating)

Here is the Python function to actually enable all new windows to float instead of tile or tab:

def set_floating(i3, event):
	event.container.command('floating enable')

Being one who prefers to have most windows not float, I set out to find a way to cause the funtion to only enable floating if a new window was in a list given in the script. Here is what works well:

# a hard coded list of windows to float by default
FLOATERS = ['Mate-terminal', 'Firefox', 'vlc', 'Caja', 'URxvt', 'UXTerm', 'xterm']

def set_floating(i3, event):
    for floater in FLOATERS:
        if event.container.window_class == floater:
            event.container.command('floating enable, resize set 1000 700, \
                move absolute position center')
			break

The essential idea is to compare the new window class to names in the list, and if there is a match, then forget about the remainder of the list and get on with floating the window. In fact, float the window, resize it moderately, and center it on the screen.

Automatic Scaling for i3 Floating Windows

To make the linux system more usable across different machines, or for convenience if changing monitors / screen resolution, use a different setup and add another Python module to the listener script.

Put the desired percent scaling (width and height) into the i3 config file as arguments to call the i3-listener:


# use a listener script to invoke tools using i3-ipc; include
# arguments for percentage scaling of floating window WIDTH and HEIGHT
 /usr/bin/i3-listener 75 85

Install the PyAutoGUI python module, which will be used to get the current screen resolution. Then, use the following version of i3-listener to calculate floating window dimensions and execute a function to center and resize floating windows. In this script, windows will not float by default. Instead, the user must manually toggle floating for a window. When the window renders, it will be scaled and centered.


#!/usr/bin/env python3


import pyautogui
from i3ipc import Connection, Event
import sys

i3 = Connection()
SCREEN_WIDTH, SCREEN_HEIGHT = pyautogui.size()
WINDOW_WIDTH = int(int(SCREEN_WIDTH) * (float(sys.argv[1]) * 0.01))
WINDOW_HEIGHT = int(int(SCREEN_HEIGHT) * (float(sys.argv[2]) * 0.01))


def window_resize(i3, event):
    WINDOW_COMMAND = 'move absolute position center, resize set '+ \
        str(WINDOW_WIDTH) + ' ' + str(WINDOW_HEIGHT)
    print(WINDOW_COMMAND)
    event.container.command(WINDOW_COMMAND)


# Float windows manually, but center and size as
# a proportion of screen resolution.
i3.on('window::floating', window_resize)

i3.main()

There are possible ways to make this more efficient or user friendly. One way is to change from a hard coded list to a user editable list kept in the home directory. That could be read on login, for example. For faster execution, these tasks could be accomplished in a binary compiled from Go instead of running in Python. In this instance the latency in question is a matter of milliseconds, but milliseconds add up. If the entire system is crafted with the intention of minimizing delays, it can be beautifully responsive.



Tags: i3, i3wm, floating windows, i3-ipc

©2005 - 2020 AB9IL, All Rights Reserved.
About, Contact, Privacy Policy and Affiliate Disclosure, XML Sitemap.