web-greeter icon indicating copy to clipboard operation
web-greeter copied to clipboard

Prompt Autofocus Support

Open TheWisker opened this issue 1 year ago • 2 comments

Environment

  • OS: ArchLinux
  • web-greeter version: 3.5.3

Description of feature

When making some changes and improvements to Shikai Theme, I wanted to implement an autofocus feature for the password prompt, which would focus the prompt when the theme gets loaded, so the user does not have to click on it manually. In theory, this is something simple to do and, consequently, I achieved it by adding the following code to get triggered on the prompt load event:

setTimeout(() => {document.getElementById("password").focus();}, 250);

The problem is this only seems to work when running the greeter on a single monitor or inside a session with and without the -d flag.

What I could deduct from some tests I did is that when using more than one monitor each monitor behaves like a separate tab/window and only one of them has 'focus'. As the .focus() function only gives focus to the element if the tab is active, the element does not get focused. Particularly, in my situation, the secondary screen, that only shows a wallpaper, appears to be the one focused, thus preventing the primary screen, that has the prompt, to get focused/active and the .focus() function to have any effect. My mouse always appears on the secondary screen and sometimes when I click on the primary screen the .focus() function seems to take effect as the prompt gets focused.

Possible solutions

This is a list of possible solutions I came with:

  • Set the primary screen to get focused/active by default
  • Add a configuration option to select which screen gets focus on greeter start
  • Add some method in the API to change focus from one screen to another

The list of solutions is based on the assumption that all of my deductions are correct and the greeter does work like that internally. In case I'm wrong feel free to correct me :)

Thanks for making the greeter

TheWisker avatar Nov 15 '24 02:11 TheWisker

Hi! I made an update in the master branch to focus the primary screen at start. Let me know if it works!

JezerM avatar Nov 19 '24 04:11 JezerM

Thank you! It works flawlessly. Sorry for my absence even when you went out of you way to fix this. Thanks for the patch and I will continue to use and support this project whenever I can.

Also, if its not much of a hassle, I recommend you update the AUR package you maintain to include these changes. I use a custom version of the package to install it on my system but there probably are people who will like the fix.

Here is my version of the PKGBUILD:

pkgname=web-greeter
pkgver=3.5.3
pkgrel=2
pkgdesc="A modern, visually appealing greeter for LightDM"
arch=('x86_64')
url="https://github.com/JezerM/web-greeter"
license=('GPL-3.0-or-later')
depends=('lightdm' 'python3' 'python-gobject' 'python-pyqt5' 'python-pyqt5-webengine' 'python-ruamel-yaml' 'python-pyinotify' 'python-xlib' 'qt5-webengine' 'qt5-webengine' 'gobject-introspection' 'libxcb' 'libx11' 'hicolor-icon-theme' 'glibc')
makedepends=('rsync' 'zip' 'make' 'patch' 'gcc' 'typescript' 'git')
checkdepends=()
optdepends=('acpid: brightness control and battery status support')
provides=()
conflicts=('nody-greeter' 'sea-greeter')
replaces=()
backup=('etc/lightdm/web-greeter.yml')
options=()
install=
changelog=
source=("${pkgname}-${pkgver}::git+https://github.com/JezerM/web-greeter#tag=${pkgver}" 'package.patch' 'v3.5.3-to-0bfa7f0.patch')
noextract=()
validpgpkeys=()
sha512sums=('9f91157806b1377d78cace041091002477b02d83d1662cbbf27f22c1356266b9f55afe010849f86ae9ba08345eb3155c481f1bf905d31f1f53944e65717000ff'
'8146f3e6047fff6ebd24cd6a2fda91322e75bef24d54cad5112e4f0daffc4f0713505f062dfb9c24255de0c2a08856f3224fe57a668247941eba73f434cad0d6'
'aad943b08e6f69e05250ae3840a98dd54eb7ef0e9b3ccb0ac3e7f5890eae8a06e4a866e2108cb23a11aa4b0d4c56f65e82ff6e1658ecb098ac7f0e48e5ada140')

prepare() {
    patch -d "${srcdir}/${pkgname}-${pkgver}" --strip=1 --forward --input="${srcdir}/package.patch"
    patch -d "${srcdir}/${pkgname}-${pkgver}" --strip=1 --forward --input="${srcdir}/v3.5.3-to-0bfa7f0.patch"
    git -C "${srcdir}/${pkgname}-${pkgver}" submodule update --init --recursive
}

build() {
    make -j1 -C "${srcdir}/${pkgname}-${pkgver}" build
}

package() {
    make -C "${srcdir}/${pkgname}-${pkgver}" DESTDIR="${pkgdir}/" install
}

I think it only differs with your current version by the lines:

source=("${pkgname}-${pkgver}::git+https://github.com/JezerM/web-greeter#tag=${pkgver}" 'package.patch' 'v3.5.3-to- patch -d "${srcdir}/${pkgname}-${pkgver}" --strip=1 --forward --input="${srcdir}/v3.5.3-to-0bfa7f0.patch"

And that I bumped the pkgrel to 2.

Also, the patch is simply the diff of the current version and your latest commit:

diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index a36df87..4494aa8 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -10,11 +10,18 @@ assignees: ''
 ## Environment
 - OS: [e.g. Ubuntu 21.04]
 - web-greeter version: output of `web-greeter --version`
+- LightDM version: output of `lightdm --version`
 
 ## Bug description
 A clear and concise description of what the bug is.
 
-<!--Include web-greeter's log if applicable-->
+<!--
+Include web-greeter's log if applicable:
+- `/var/log/lightdm/lightdm.log`
+- `/var/log/lightdm/seat0-greeter.log`
+
+Make sure these logs are from after the issue occurred or when it's happening.
+-->
 
 ## Steps to reproduce
 Steps to reproduce the behavior.
@@ -22,5 +29,5 @@ Steps to reproduce the behavior.
 ## Expected behavior
 A clear and concise description of what you expected to happen.
 
-## **Screenshots**
+## Screenshots
 If applicable, add screenshots to help explain your problem.
diff --git a/Makefile b/Makefile
index 02bcca4..622933b 100644
--- a/Makefile
+++ b/Makefile
@@ -191,7 +191,7 @@ build_dist_files: $(dist_local/web-greeter.1) $(dist_local/news) $(dist_local/me
 
 # Config files
 config/web-greeter := $(abspath ${DESTDIR}/etc/lightdm/web-greeter.yml)
-config/lightdm-wrapper := $(abspath ${DESTDIR}/etc/xdg/lightdm/lightdm.conf.d/90-greeter.wrapper.conf)
+config/lightdm-wrapper := $(abspath ${DESTDIR}/etc/xdg/lightdm/lightdm.conf.d/90-greeter-wrapper.conf)
 config/Xgreeter := $(abspath ${DESTDIR}/etc/lightdm/Xgreeter)
 
 config_local/web-greeter := $(abspath ${INSTALL_ROOT}/etc/lightdm/web-greeter.yml)
@@ -238,21 +238,23 @@ $(bin_local/web-greeter): build_install_root $(resources.py) $(bin/screensaver.s
 # Useful rules
 .PHONY: build
 build: $(bin_local/web-greeter)
-	@echo "✔ Build succeded"
+	@echo "✔ Build succeeded"
 
 .PHONY: install
 install: build
 	[ -e "${DESTDIR}" ] || mkdir -p "${DESTDIR}"
 	cp -R "${INSTALL_ROOT}"/* "${DESTDIR}"
-	@echo "✔ Install succeded"
+	@echo "✔ Install succeeded"
 
 # Uninstall everything except themes and web-greeter.yml
 uninstall_preserve:
+	@rm -rf "${DESTDIR_PREFIX}/lib/web-greeter/"
 	@rm -f "${dist/web-greeter.1}"
 	@rm -f "${dist/app-desktop}"
 	@rm -f "${dist/xg-desktop}"
 	@rm -f "${dist/metainfo}"
 	@rm -f "${dist/news}"
+	@rm -f "${dist/app-icon-scalable}"
 	@rm -f "${config/lightdm-wrapper}"
 	@rm -f "${config/Xgreeter}"
 	@rm -f "${bin/web-greeter}"
@@ -265,14 +267,14 @@ uninstall_preserve:
 
 # Uninstall everything
 uninstall_all: uninstall_preserve
-	@rm -rf "${config/web-greeter}"
-	@rm -rf "${DESTDIR_PREFIX}/web-greeter/"
+	@rm -rf "${DESTDIR_PREFIX}/share/web-greeter/"
+	@rm -f "${config/web-greeter}"
 
 .PHONY: uninstall
 uninstall: uninstall_preserve
-	@echo " Themes are not uninstalled. Remove them manually or use \`make uninstall_all\`:\
+	@echo -e " Themes are not uninstalled. Remove them manually or use \`make uninstall_all\`:\
 		\n${DESTDIR_PREFIX}/share/web-greeter"
-	@echo " web-greeter config was not uninstalled. Remove it manually or use \`make uninstall_all\`:\
+	@echo -e " web-greeter config was not uninstalled. Remove it manually or use \`make uninstall_all\`:\
 		\n${config/web-greeter}"
 
 run: $(resources.py)
diff --git a/NEWS.md b/NEWS.md
index 064eb9e..8298ec5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,6 @@
 # Change Log
 
-## [3.5.3](https://github.com/JezerM/web-greeter/tree/3.5.3) ~ 2023-03-30
+## [3.5.3](https://github.com/JezerM/web-greeter/tree/3.5.3) ~ 2024-03-30
 
 **Changes:**
   * Fixed ruamel.yaml usage
diff --git a/README.md b/README.md
index d171961..27d8167 100644
--- a/README.md
+++ b/README.md
@@ -196,6 +196,6 @@ web-greeter related import errors:
 [bat_widget]: https://github.com/lcpz/lain/blob/master/widget/bat.lua "Battery widget"
 [lain]: https://github.com/lcpz/lain "Lain awesome library"
 [WebArchive]: https://web.archive.org/web/20190524032923/https://doclets.io/Antergos/web-greeter/stable "Web Archive"
-[web-greeter-docs]: https://jezerm.github.io/web-greeter-page/docs/ "Documentation"
+[web-greeter-docs]: https://web-greeter-page.vercel.app "Documentation"
 [live_demo]: https://jezerm.github.io/web-greeter-themes/ "Live Demo"
 [releases]: https://github.com/JezerM/web-greeter/releases "Releases"
diff --git a/src/bridge/Greeter.py b/src/bridge/Greeter.py
index 4119655..5f7c469 100644
--- a/src/bridge/Greeter.py
+++ b/src/bridge/Greeter.py
@@ -119,7 +119,10 @@ class Greeter(BridgeObject):
         users = LightDMUsers.get_users()
         if not users:
             return
-        user_data_dir = LightDMGreeter.ensure_shared_data_dir_sync(users[0].get_name())
+        try:
+            user_data_dir = LightDMGreeter.ensure_shared_data_dir_sync(users[0].get_name())
+        except Exception:
+            return
         if user_data_dir is None:
             return
         self._shared_data_directory = user_data_dir.rpartition('/')[0]
diff --git a/src/browser/browser.py b/src/browser/browser.py
index 8928550..cbced5c 100644
--- a/src/browser/browser.py
+++ b/src/browser/browser.py
@@ -225,10 +225,20 @@ class Application:
 
     def show(self):
         """Show window"""
+        primary: WindowAbstract | None = None
         for win in self.windows:
+            if win.is_primary:
+                primary = win
+                continue
             win.window.show()
             logger.debug("Web Greeter started win: %s", str(win.meta.id))
 
+        if primary and primary.is_primary:
+            primary.window.show()
+            primary.window.activateWindow()
+            primary.window.raise_()
+            logger.debug("Web Greeter started win: %s", str(primary.meta.id))
+
     def run(self) -> int:
         """Runs the application"""
         logger.debug("Web Greeter started")
diff --git a/src/browser/window.py b/src/browser/window.py
index 2506296..d361bc7 100644
--- a/src/browser/window.py
+++ b/src/browser/window.py
@@ -125,7 +125,7 @@ class BrowserWindow(MainWindow):
     win_view: QWebEngineView
     win_page: WebPage
     dev_view: QWebEngineView
-    dev_page: QWebEnginePage
+    dev_page: WebPage
     dev_tools_enabled: bool = False
     bridge_initialized: bool
 
@@ -235,7 +235,7 @@ class BrowserWindow(MainWindow):
 
     def _init_devtools(self):
         self.dev_view = QWebEngineView(parent=self)
-        self.dev_page = QWebEnginePage()
+        self.dev_page = WebPage()
 
         self.dev_view.setPage(self.dev_page)
         self.dev_view.setObjectName("Devtools view")

Hope it helps and many thanks!

TheWisker avatar Jul 20 '25 15:07 TheWisker