fix: cinnamon hotkeys problem (#28)

* chore: revert "fix: revert "fix: cinnamon hotkeys problem (#24)" (#26)"

This reverts commit cd17d9d6b1.

* fix: installment not registering keys
This commit is contained in:
dashio
2025-12-15 23:22:45 -03:00
committed by GitHub
parent cd17d9d6b1
commit fb764e3510
16 changed files with 255 additions and 344 deletions

View File

@@ -1,8 +1,7 @@
# udev rules for Windows 11 Clipboard History
# Allows non-root users in the 'input' group to access input devices for global hotkeys
# Input devices (keyboards) - needed for evdev global hotkey detection
KERNEL=="event*", SUBSYSTEM=="input", MODE="0660", GROUP="input"
# Input devices (keyboards) - TAG+="uaccess" allows logged-in user to read events
KERNEL=="event*", SUBSYSTEM=="input", MODE="0660", GROUP="input", TAG+="uaccess"
# uinput device - needed for kernel-level keyboard simulation (paste injection)
KERNEL=="uinput", SUBSYSTEM=="misc", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"

View File

@@ -49,37 +49,55 @@ if [ -f "$BINARY_PATH" ] && [ ! -L "$BINARY_PATH" ]; then
cat > "$BINARY_PATH" << 'WRAPPER'
#!/bin/bash
# Wrapper script for win11-clipboard-history
# Cleans environment to avoid Snap library conflicts
# Forces X11/XWayland for better window positioning support
BINARY="/usr/lib/win11-clipboard-history/win11-clipboard-history-bin"
# Always use clean environment to avoid library conflicts
# GDK_BACKEND=x11 forces XWayland on Wayland sessions for window positioning
exec env -i \
HOME="$HOME" \
USER="$USER" \
SHELL="$SHELL" \
TERM="$TERM" \
DISPLAY="${DISPLAY:-:0}" \
XAUTHORITY="$XAUTHORITY" \
WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \
XDG_SESSION_TYPE="$XDG_SESSION_TYPE" \
XDG_CURRENT_DESKTOP="$XDG_CURRENT_DESKTOP" \
XDG_SESSION_CLASS="$XDG_SESSION_CLASS" \
DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \
PATH="/usr/local/bin:/usr/bin:/bin" \
LANG="${LANG:-en_US.UTF-8}" \
LC_ALL="${LC_ALL:-}" \
GDK_BACKEND="x11" \
"$BINARY" "$@"
# Set GDK_BACKEND=x11 for window positioning support, but inherit full environment
# to avoid issues with DBus, display variables, etc.
export GDK_BACKEND="x11"
exec "$BINARY" "$@"
WRAPPER
chmod +x "$BINARY_PATH"
echo -e "${GREEN}${NC} Created wrapper script for Snap compatibility"
fi
# Ensure input group exists
# Install application icons to standard system paths for better DE compatibility (especially Cinnamon)
install_icons() {
echo -e "${BLUE}Installing application icons...${NC}"
# Source icons from the installed package
local ICON_SRC_DIR="/usr/share/icons/hicolor"
local PIXMAPS_DIR="/usr/share/pixmaps"
# Create pixmaps directory if it doesn't exist
mkdir -p "$PIXMAPS_DIR"
# Install main icon to pixmaps (fallback location that most DEs check)
if [ -f "$ICON_SRC_DIR/128x128/apps/win11-clipboard-history.png" ]; then
install -m 644 "$ICON_SRC_DIR/128x128/apps/win11-clipboard-history.png" \
"$PIXMAPS_DIR/win11-clipboard-history.png"
echo -e "${GREEN}${NC} Installed icon to pixmaps"
elif [ -f "$LIB_DIR/icons/icon.png" ]; then
install -m 644 "$LIB_DIR/icons/icon.png" \
"$PIXMAPS_DIR/win11-clipboard-history.png"
echo -e "${GREEN}${NC} Installed icon to pixmaps (from lib)"
fi
# Update icon cache if gtk-update-icon-cache is available
if command -v gtk-update-icon-cache &> /dev/null; then
gtk-update-icon-cache -f -t "$ICON_SRC_DIR" 2>/dev/null || true
fi
# Also update icon cache for all themes
if command -v update-icon-caches &> /dev/null; then
update-icon-caches /usr/share/icons/* 2>/dev/null || true
fi
}
install_icons
# Ensure input group exists (needed for paste simulation via uinput)
if ! getent group input > /dev/null 2>&1; then
echo -e "${BLUE}Creating 'input' group...${NC}"
groupadd input
@@ -89,8 +107,8 @@ fi
UDEV_RULE="/etc/udev/rules.d/99-win11-clipboard-input.rules"
cat > "$UDEV_RULE" << 'EOF'
# udev rules for Windows 11 Clipboard History
# Input devices (keyboards) - needed for evdev global hotkey detection
KERNEL=="event*", SUBSYSTEM=="input", MODE="0660", GROUP="input"
# Input devices (keyboards) - TAG+="uaccess" allows logged-in user to read events
KERNEL=="event*", SUBSYSTEM=="input", MODE="0660", GROUP="input", TAG+="uaccess"
# uinput device - needed for kernel-level keyboard simulation (paste injection)
KERNEL=="uinput", SUBSYSTEM=="misc", MODE="0660", GROUP="input", OPTIONS+="static_node=uinput"
EOF
@@ -127,14 +145,13 @@ if [ -n "$ACTUAL_USER" ] && [ "$ACTUAL_USER" != "root" ]; then
fi
fi
# Grant IMMEDIATE access using ACLs (no logout required!)
# This allows the user to start using the app right away
# The group membership above ensures it works after reboot too
# Grant IMMEDIATE access to uinput using ACLs (no logout required!)
# This allows the user to start using paste features right away
grant_immediate_access() {
local user="$1"
if [ -z "$user" ] || [ "$user" = "root" ]; then
return
return 0 # Success - nothing to do for root
fi
# Check if setfacl is available
@@ -161,7 +178,7 @@ grant_immediate_access() {
fi
done
# Grant ACL access to uinput
# Grant ACL access to uinput (for paste keystroke simulation)
if [ -e /dev/uinput ]; then
setfacl -m "u:${user}:rw" /dev/uinput 2>/dev/null || true
fi
@@ -175,8 +192,6 @@ grant_immediate_access() {
}
# Determine if logout is needed:
# - If user was already in input group, no logout needed
# - If ACLs were granted successfully, no logout needed
# - Otherwise, logout is needed for new group membership to take effect
NEEDS_LOGOUT=false
if [ "$USER_ALREADY_IN_INPUT_GROUP" = true ]; then
@@ -312,11 +327,7 @@ echo -e "${GREEN}║ Windows 11 Clipboard History installed!
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""
if [ "$NEEDS_LOGOUT" = true ]; then
echo -e "${YELLOW}⚠ Please log out and log back in for permissions to apply.${NC}"
echo ""
echo "After logging back in, the app will start automatically."
elif [ "$APP_LAUNCHED" = true ]; then
if [ "$APP_LAUNCHED" = true ]; then
echo -e "${GREEN}✓ App is now running! Press Super+V or Ctrl+Alt+V to open.${NC}"
else
echo -e "${GREEN}✓ Ready to use!${NC}"
@@ -325,6 +336,11 @@ else
echo "To start now, find 'Clipboard History' in your application menu."
fi
if [ "$NEEDS_LOGOUT" = true ]; then
echo ""
echo -e "${YELLOW}Note: you may need to log out and back in to apply certain pasting permissions.${NC}"
fi
echo ""
exit 0

View File

@@ -1,31 +1,13 @@
#!/bin/bash
# Wrapper script for win11-clipboard-history
# Cleans environment to avoid Snap library conflicts
# Forces X11/XWayland for better window positioning support
# Binary location
BINARY="/usr/lib/win11-clipboard-history/win11-clipboard-history-bin"
# Force X11/XWayland for better window positioning support
# Set GDK_BACKEND=x11 for window positioning support, but inherit full environment
# to avoid issues with DBus, display variables, etc.
# Wayland restricts cursor_position() and set_position() for security
# XWayland allows these operations while still running on Wayland session
WEBKIT_DISABLE_COMPOSITING_MODE=1
# Always use clean environment to avoid library conflicts from Snap, Flatpak, etc.
exec env -i \
HOME="$HOME" \
USER="$USER" \
SHELL="$SHELL" \
TERM="$TERM" \
DISPLAY="${DISPLAY:-:0}" \
XAUTHORITY="$XAUTHORITY" \
WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \
XDG_SESSION_TYPE="$XDG_SESSION_TYPE" \
XDG_CURRENT_DESKTOP="$XDG_CURRENT_DESKTOP" \
XDG_SESSION_CLASS="$XDG_SESSION_CLASS" \
DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \
PATH="/usr/local/bin:/usr/bin:/bin" \
LANG="${LANG:-en_US.UTF-8}" \
LC_ALL="${LC_ALL:-}" \
GDK_BACKEND="x11" \
"$BINARY" "$@"
export GDK_BACKEND="x11"
exec "$BINARY" "$@"