Skip to content

Commit

Permalink
Merge pull request #15 from nwg-piotr/empty-window
Browse files Browse the repository at this point in the history
Allow to display login form on selected monitors only
  • Loading branch information
nwg-piotr authored Jun 3, 2024
2 parents bc22931 + 9183ebc commit dc8287c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ worked pretty well. However, it brings QT dependencies, and my stuff is all GTK-
framework, so couldn't adjust the greeter to my taste. The next choice was LightDM with [my modification](https://github.com/nwg-piotr/lightdm-nwg-greeter)
of the [LightDM Elephant Greeter](https://github.com/max-moser/lightdm-elephant-greeter) by Maximilian Moser. It looked
well, but LightDM would happen to hang way too often. Then I gave a try to greetd, and that was it. I only needed
a nice graphical greeter based on GTK3. Since there was no such thing, I had to develop my own.
a nice graphical greeter based on GTK3. Since there was no such thing, I had to develop one.

## Features

Expand All @@ -38,6 +38,13 @@ a nice graphical greeter based on GTK3. Since there was no such thing, I had to
- Hyprland or sway Wayland compositor;
- gnome-themes-extra (recommended, as it provides us with the default Adwaita theme).

## Make dependencies

- python-build
- python-installer
- python-wheel
- python-setuptools

## Installation

[![Packaging status](https://repology.org/badge/vertical-allrepos/nwg-hello.svg)](https://repology.org/project/nwg-hello/versions)
Expand Down Expand Up @@ -110,6 +117,7 @@ Copy `/etc/nwg-hello/nwg-hello-default.json` to `/etc/nwg-hello/nwg-hello.json`
}
],
"monitor_nums": [],
"form_on_monitors": [],
"delay_secs": 1,
"cmd-sleep": "systemctl suspend",
"cmd-reboot": "systemctl reboot",
Expand All @@ -127,6 +135,7 @@ Copy `/etc/nwg-hello/nwg-hello-default.json` to `/etc/nwg-hello/nwg-hello.json`
- `"session_dirs"`: comma-separated paths to session directories. Modify only if you know well what you're doing.
- `"custom_sessions"`: greetd can run whatever starts from the command line. This way we can add `bash`, `zsh` or something else here. The `"name"` field is the display name. The `"exec"` field is a command.
- `"monitor_nums"`: leave as is to see the greeter on all monitors. Set e.g. `[0, 2]` for it to appear on the 1st and 3rd one.
- `"form_on_monitors"`: which of above monitors to display the login form on (just the wallpaper on the rest).
- `"delay_secs"`: some monitors take longer to turn on. In the meantime the greeter may behave oddly on other monitors. If it happens to restart/blink, increase this value. If you only have one monitor and no discrete GPU, you may probably set `0` here.
- `"cmd-sleep"`, `"cmd-reboot"`, and `"cmd-poweroff"` are pre-defined for systemd-based systems. Use whatever works for you.
- `"gtk-theme"`, `"gtk-icon-theme"` and `"gtk-cursor-theme"` are of little importance as long, as you use classes and IDs from the default css style sheet.
Expand Down
6 changes: 5 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

# Make sure you have 'python-build' 'python-installer' 'python-wheel' and 'python-setuptools' installed

install -D -m 644 -t /etc/nwg-hello/ nwg-hello-default.json
install -D -m 644 -t /etc/nwg-hello/ nwg-hello-default.css
install -D -m 644 -t /etc/nwg-hello/ hyprland.conf
Expand All @@ -14,4 +16,6 @@ install -Dm644 -t /var/cache/nwg-hello cache.json -o greeter
install -Dm 644 -t "/usr/share/licenses/nwg-hello" LICENSE
install -Dm 644 -t "/usr/share/doc/nwg-hello" README.md

python3 setup.py install --optimize=1
python -m build --wheel --no-isolation
[ -f /usr/bin/nwg-hello ] && sudo rm /usr/bin/nwg-hello
python -m installer dist/*.whl
1 change: 1 addition & 0 deletions nwg-hello-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"monitor_nums": [],
"form_on_monitors": [],
"delay_secs": 1,
"cmd-sleep": "systemctl suspend",
"cmd-reboot": "systemctl reboot",
Expand Down
8 changes: 6 additions & 2 deletions nwg_hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"template-name": "",
"custom_sessions": [],
"monitor_nums": [],
"form_on_monitors": [],
"delay_secs": 1,
"lang": "",
"cmd-sleep": "systemctl suspend",
Expand Down Expand Up @@ -171,8 +172,11 @@ def main():
for i in reversed(range(display.get_n_monitors())):
if not settings["monitor_nums"] or i in settings["monitor_nums"]:
monitor = display.get_monitor(i)
win = GreeterWindow(client, settings, sessions, x_sessions, users, monitor, voc, cache, args.log, args.test)
windows.append(win)
if not settings["form_on_monitors"] or i in settings["form_on_monitors"]:
win = GreeterWindow(client, settings, sessions, x_sessions, users, monitor, voc, cache, args.log, args.test)
windows.append(win)
else:
win = EmptyWindow(monitor, args.log, args.test)

GLib.timeout_add(1, move_clock)
Gtk.main()
Expand Down
31 changes: 31 additions & 0 deletions nwg_hello/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,34 @@ def login(self, btn):
resp = greetd(self.client, jreq, log=self.log)
if "type" in resp and resp["type"] == "success":
sys.exit()


class EmptyWindow(Gtk.Window):
def __init__(self, monitor, log, test):
eprint(f"Creating EmptyWindow on {monitor}", log=log)

self.test = test

Gtk.Window.__init__(self)

self.connect('destroy', Gtk.main_quit)
self.connect("key-release-event", self.handle_keyboard)

GtkLayerShell.init_for_window(self)
GtkLayerShell.set_monitor(self, monitor)
GtkLayerShell.set_layer(self, GtkLayerShell.Layer.OVERLAY)
GtkLayerShell.set_keyboard_mode(self, GtkLayerShell.KeyboardMode.ON_DEMAND)
GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.TOP, True)
GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.BOTTOM, True)
GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.LEFT, True)
GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.RIGHT, True)
GtkLayerShell.set_exclusive_zone(self, -1)

self.show()

def handle_keyboard(self, w, event):
if event.type == Gdk.EventType.KEY_RELEASE:
if self.test and event.keyval == Gdk.KEY_Escape:
Gtk.main_quit()

return True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(f_name):

setup(
name='nwg-hello',
version='0.2.0',
version='0.2.1',
description='GTK3-based greeter for greetd',
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit dc8287c

Please sign in to comment.