(autokey, Linux only) Script to move Messages window on 2nd monitor

Various topics about the game, the website, or anything else Freeciv related that doesn't fit elsewhere.
Post Reply
wildlingofthewall
Posts: 7
Joined: Mon Aug 31, 2020 9:10 am

(autokey, Linux only) Script to move Messages window on 2nd monitor

Post by wildlingofthewall »

I've had a critical first world problem with the Messages windows getting closed while floating on the 2nd monitor. Now and then some action or turn change switches focus and next enter or space press closes it. Then you have to mess with reopening, dragging, resizing again again. Big bother.

Finally I caved in and dug out this autokey (https://github.com/autokey/autokey) sequence to assist. Seems to be working as intended. It's similar to autohotkey on Windows, Automator on Mac or a macro inside a spreadsheet and other tools like that.

It closes all open panes and then moves Messages to a floating window on the 2nd monitor. Keep Diplomacy floating over there beforehand to prevent cancelling upcoming meetings. Use Alt-Tab as usual to switch focus back to main map window.

Here's the commented script, ask away if anything is unclear:
https://board.net/p/frcv_atk
wildlingofthewall
Posts: 7
Joined: Mon Aug 31, 2020 9:10 am

Re: (autokey, Linux only) Script to move Messages window on 2nd monitor

Post by wildlingofthewall »

minor edits, timings hard to nail, seems to be dependent of general CPU usage, just run it twice if it fails

Code: Select all

# problem:
# when using floating windows, due to shifting window focus inbetween turns and user actions,
# the floating messages windows is frequently closed by mistake
# Re-opening, dragging, resizing involves a lot of mouse hassling :)   

# setup:
# dual monitor on top of each other
# resolutions 720p above, 768p below
# main window on top monitor

# goal:
# messages (msg) displayed as a floating window on bottom monitor

# tasks:
#1 open msg pane
#2 undock msg pane as a floating window
#3 drag floating window to monitor below
#4 resize it

# refs:
# https://github.com/autokey/autokey/wiki/Emitting-Keyboard-Events
# https://github.com/autokey/autokey/wiki/Mouse-Control
# https://github.com/autokey/autokey/wiki/Key-Combinations

#################
###1 to get a fixed position for msg pane, right next to view and chat, close all other panes

#1.1 switch to map pane to avoid pane sequence mess up
keyboard.send_keys("<f1>") 
time.sleep(0.5)

#1.2 open msg pane as the last in the row
keyboard.send_keys("<f9>")

#1.3 close all open panes
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")
keyboard.send_keys("<escape>")

#1.4 reopen msg pane to the fixed position, next to view and chat
keyboard.send_keys("<f9>") 
time.sleep(0.5)

#################
###2 double-click msg pane to open it as a floating window

mouse.click_absolute(330, 700, 1)
mouse.click_absolute(330, 700, 1)
time.sleep(0.5)

#################
###3 move floating window to monitor below

#3.1 use window manager hotkey to click open the right-click (aka context) menu 
# this could also be achieved with
# mouse.click_relative(x, y, 3)

keyboard.press_key("<alt>")
keyboard.press_key("<f2>")
keyboard.release_key("<f2>")
keyboard.release_key("<alt>")
time.sleep(0.6)

# because
# keyboard.send_keys("<alt>+<f2>")
# doesn't work for me

#3.2 click the move menu entry, 100 pixels below 

mouse.click_relative_self(0, 100, 1)
time.sleep(0.5)

# because either of these cursor moves doesn't work consistently for me:

# keyboard.send_key("<down>")
# keyboard.send_keys("<down>")

# keyboard.fake_keypress("<down>", repeat=4)
# nor 4 x:
# keyboard.fake_keypress("<down>")

#3.3 place the floating window where preferred on bottom monitor
# pixel position relative to exact display settings, ie. where they are placed in settings 

mouse.click_absolute(20, 753, 1)
time.sleep(0.3)

#################
###4 resize floating window 

#4.1 open context menu again
keyboard.press_key("<alt>")
keyboard.press_key("<f2>")
keyboard.release_key("<f2>")
keyboard.release_key("<alt>")
time.sleep(0.5)

#4.1 click the resize menu entry, 111 pixels below 

mouse.click_relative_self(0, 111, 1)
time.sleep(0.5)
#time.sleep(1)
#4.2 resize as preferred

mouse.click_absolute(943, 1442, 1)

###
#5 rest your soul and mouse hands forever
Post Reply