Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Stjerm Layout Like Functionality #298

Closed
ghost opened this issue Nov 21, 2020 · 6 comments
Closed

Enhancement: Stjerm Layout Like Functionality #298

ghost opened this issue Nov 21, 2020 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 21, 2020

Stjerm Repo: https://github.com/stjerm/stjerm

Would ya'll consider adding layout binding like that of Stjerm? With Stjerm one can pass a position argument of left, right, top, and bottom as well as width and height arguments. From there, you can bind to a toggle key that shows/hides the terminal. What this allows me to do is something like the follow:

exec stjerm -k f8 -p left -h 800 -w 700 &
exec stjerm -k f9  -p right -h 800 -w 700  &
exec stjerm -k f12 -p top -h 500 -w 700 &
exec stjerm -k f10 -p bottom -h 500 -w 700 &

It binds a terminal to the respective key and sets the width and height. From there, it's toggleable and shows on the monitor the mouse is currently on.

For terminator, I know there is the --geometry argument and I know there is a toggle key setting one can set. I don't see a cli argument to set the keybinding. I know that -p is already used to load a profile. So, a different argument is needed there. But, it would be nice to bind unique key's or combo of keys that show or hide their respective terminals. Additionally, positioning the window automatically based on the monitor the mouse is on would be a great addition.

I've been looking through Terminator's code but am a little unclear on where to focus/start.

Monitor data can be gotten with something like this but modified accordingly:

def getMonitorData(self):
    screen   = self.builder.get_object("Main_Window").get_screen()
    monitors = []
    for m in range(screen.get_n_monitors()):
        monitors.append(screen.get_monitor_geometry(m))

    for monitor in monitors:
        print("{}x{}+{}+{}".format(monitor.width, monitor.height, monitor.x, monitor.y))

    return monitors

To get mouse position, something like the following might work. from there, that data is compared to the monitor data and the window is positioned appropriately on the toggle action. The package python-xlib would be needed.

from Xlib import display

def getMousePosition():
    data = display.Display().screen().root.query_pointer()._data
    return data["root_x"], data["root_y"]
@mattrose
Copy link
Member

There's a lot to unpack here but the first big problem I see is that the Xlib stuff most likely won't work on Wayland, or MacOS (It's not officially supported, but I run terminator on my mac a lot). There are Gtk and Gdk calls that will work across all three, though, I'm pretty sure. That way we also wouldn't need to import another lib.

@mattrose mattrose added the enhancement New feature or request label Nov 21, 2020
@ghost
Copy link
Author

ghost commented Nov 21, 2020

@mattrose

I'm fine with trying to use Gtk and Gdk calls to try and get the pointer. The only thing is is that I've always found it hard to try and translate the C implementation back to Python. So, I have been lazy and mostly used the above option because it was the simplest for me. =P Doing further googling, I'm thinking Gdk.DeviceManager.get_client_pointer would be a possible route to take.

https://stackoverflow.com/questions/24844489/how-to-use-gdk-device-get-position

@ghost
Copy link
Author

ghost commented Nov 21, 2020

@mattrose

Api Reference: https://lazka.github.io/pgi-docs/#Gdk-3.0/classes/Device.html#Gdk.Device

OK, I figured out how to use Gdk to get the pointer info. Now, this is currently setup to work with GTK 3. The methods used would be different if you're supporting older GTKs. I had to bounce about to get what the "modern" way of doing this is as the SO link I mentioned is doing an older way that uses deprecated calls.

import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk as gdk


    def getPointerPos(self)
        display = gdk.Display.get_default()
        gdk_device_manager = gdk.Display.get_default_seat(display)
        pointer = gdk_device_manager.get_pointer()
        data    = pointer.get_position()

        print("x: {}, y: {}".format(data.x, data.y))
        return data.x, data.y

@mattrose
Copy link
Member

mattrose commented Jan 4, 2021

Have you tried to do this with layouts? I've been reading over the functionality that you requested and it looks to me like Layouts are exactly what you want. terminator -l $layout will open a window with the specified geometry. From there you could hook a keybinding into your window manager that would do what you desire.

I'm also gonna be painfully honest here. I'm not going to code this feature as you described it. I may merge it, if you or somebody else writes the code in a way that won't interfere too much with maintenance, but this is an all-volunteer project, and we have limited time to work on new functionality.

@mattrose mattrose closed this as completed Jan 4, 2021
@ghost
Copy link
Author

ghost commented Jan 4, 2021

@mattrose In so far as I can tell, layouts doesn't manage the position beyond explicit x, y definitions. It doesn't position it based on which monitor the mouse is on. In addition, window hints would need to be added in order to make it function like STjerm so as to not clutter the app list when acting like a dynamically shown terminal. Sad to hear it wont be added per say but I understand why. Regardless, thank you for hearing me out.

@mattrose
Copy link
Member

mattrose commented Jan 4, 2021

Sorry to disappoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant