help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List of monitor names


From: Sam Steingold
Subject: Re: List of monitor names
Date: Thu, 15 Sep 2022 13:06:37 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)

> * uzibalqa <hmvonydn@cebgba.zr> [2022-09-15 10:52:34 +0000]:
>
>> uzibalqa uzibalqa@proton.me writes:
>> 
>> > Can one get a list of monitor names that I can use to tell emacs where
>> > to put the frame?
>> 
>> 
>> How do you plan to use the monitor names to tell Emacs where to put a
>> frame?
>
> Perhaps the user can get the monitor names and see which monitor he wants to 
> work in.

For me the solution was based on https://askubuntu.com/q/702071/80483
and https://askubuntu.com/q/702002/80483; basically you run `xrandr` and
parse its output.

--8<---------------cut here---------------start------------->8---
# configure multiple displays and
# move the windows to their appropriate displays

import subprocess
import os
import wmctrl
import re

mydisplays = [("VGA1",0,"left"),
              ("eDP1",1080,"normal"),
              ("HDMI1",3000,"left")]

def set_displays ():
    subprocess.check_call(" && ".join([
        "xrandr --output %s --pos %dx0  --rotate %s" % d for d in mydisplays]),
                          shell=True)

mywindows = [("/emacs$","VGA1"),
             ("/chrome$","HDMI1"),
             ("gnome-terminal","eDP1")]
def max_windows ():
    didi = dict([(d,x) for d,x,_ in mydisplays])
    for w in wmctrl.Window.list():
        try:
            exe = os.readlink("/proc/%d/exe" % (w.pid))
            if exe.endswith(" (deleted)"):
                print("WARNING: restart %s" % exe)
            for (r,d) in mywindows:
                if re.search(r,exe):
                    x = didi[d]
                    print("%s(%s) --> %s (%d)" % (r,exe,d,x))
                    
w.set_properties(("remove","maximized_vert","maximized_horz"))
                    w.resize_and_move(x,0,w.w,w.h)
                    w.set_properties(("add","maximized_vert","maximized_horz"))
                    break
        except OSError:
            continue

def cmdlines (cmd):
    return subprocess.check_output(cmd).splitlines()

def show_displays ():
    for l in cmdlines(["xrandr"]):
        if " connected " in l:
            print(l)

if __name__ == '__main__':
    show_displays()
    set_displays()
    show_displays()
    max_windows()
--8<---------------cut here---------------end--------------->8---



-- 
Sam Steingold (https://aphar.dreamwidth.org/) on darwin Ns 10.3.2113
https://lastingimpactpsychology.com https://steingoldpsychology.com
https://honestreporting.com https://thereligionofpeace.com https://ij.org/
Any supplier that makes enough to pay a full time lobbyist is overcharging.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]