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

Hotkey on active screen only #1883

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Rajveer86
Copy link

@Rajveer86 Rajveer86 commented Jan 25, 2023

What this PR does

This PR allows keystroke actions to be performed on only the active screen of specified screens.

Current behaviour

Currently keystroke actions behave as such:

keystroke(Control) = keystroke(Super) - performs on the active screen only, but with no way to have custom keystrokes for different screens
keystroke(Control) = keystroke(Super,Mac-Mini) - always performs on the specified screens, regardless of whether they are active, and no way to target a specific one

New behaviour (activeScreenOnly option)

This PR adds a new optional setting activeScreenOnly to keystroke actions, used as such:

keystroke(Control) = keystroke(Super,Mac-Mini,activeScreenOnly) - performs on Mac-Mini, and only when it is active

As normal, keystroke actions can be chained, meaning that we can have different shortcuts for different screens, and only when those screens are active:

keystroke(Control) = keystroke(Super,Mac-Mini:Mac-Pro,activeScreenOnly),keystroke(Alt,Laptop,activeScreenOnly) - changes Control->Super on Mac-Mini and Mac-Pro, and Control->Alt on Laptop, and only on the one that is active

Windows and macOS server specifics (disableGlobalHotkeyRegister option)

On Windows and macOS this works for both server and clients, with the exception being for keystroke actions intended for the server where the keystroke matches the condition (for instance, adding a custom action on a client, but preserving the original keystroke on the server) e.g.

keystroke(Control) = keystroke(Super,Mac-Mini,activeScreenOnly), keystroke(Alt,Server,activeScreenOnly) - this works on Server
keystroke(Control) = keystroke(Super,Mac-Mini,activeScreenOnly), keystroke(Control,Server,activeScreenOnly) - this does not work on Server

Since Barrier registers a hotkey for the keystroke condition on the server, this prevents the ability to specify the original keystroke as an action for the server. For this, a new option disableGlobalHotkeyRegister for the condition allows disabling hotkey registration with the OS. This allows the original keystroke to be performed on the server when it is in focus i.e.

keystroke(Control,disableGlobalHotkeyRegister) = keystroke(Super,Rajveer-Mac-Mini,activeScreenOnly) - this allows the original keystroke to perform on the server, akin to if we also had keystroke(Control,Server,activeScreenOnly)

Linux server specifics

On Linux, keystroke actions currently don't seem to work on the server at all. However, using disableGlobalHotkeyRegister at least allows us to achieve the same as in the above example (i.e. the server can perform the default keybind whilst clients have custom keybinds)

keystroke(Left) = keystroke(Right) - this works on Windows and macOS when focusing the server, but not Linux
keystroke(Left) = keystroke(Left) - this doesn't work on any server (but works on all when using disableGlobalHotkeyRegister)
keystroke(Left,disableGlobalHotkeyRegister) = keystroke(Right,Mac-Mini,activeScreenOnly) - but at least this allows a custom hotkey on Mac-Mini whilst still allowing the default keystroke to perform on a server on any platform

A real-world example

I want to control my Mac computers from my Windows machine, and want them to work with Windows keybinds (e.g. Ctrl+C to copy). On macOS I use Karabiner-Elements for this, but this doesn't work with Barrier. I now use the below configuration to achieve the same effect when running a Windows server:

section: screens
	Rajveer-Desktop:
		halfDuplexCapsLock = false
		halfDuplexNumLock = false
		halfDuplexScrollLock = false
		xtestIsXineramaUnaware = false
		preserveFocus = false
		switchCorners = none
		switchCornerSize = 0
	Rajveer-Mac-Mini:
		ctrl = super
		alt = ctrl
		super = alt
		halfDuplexCapsLock = false
		halfDuplexNumLock = false
		halfDuplexScrollLock = false
		xtestIsXineramaUnaware = false
		preserveFocus = false
		switchCorners = none
		switchCornerSize = 0
	rajveer-mp:
		ctrl = super
		alt = ctrl
		super = alt
		halfDuplexCapsLock = false
		halfDuplexNumLock = false
		halfDuplexScrollLock = false
		xtestIsXineramaUnaware = false
		preserveFocus = false
		switchCorners = none
		switchCornerSize = 0
end

section: aliases
end

section: links
	Rajveer-Desktop:
		right = Rajveer-Mac-Mini
		left = rajveer-mp
	Rajveer-Mac-Mini:
		left = Rajveer-Desktop
	rajveer-mp:
		right = Rajveer-Desktop
end

section: options
	relativeMouseMoves = false
	screenSaverSync = true
	win32KeepForeground = false
	clipboardSharing = true
	switchCorners = none 
	switchCornerSize = 0
	keystroke(Control+Left,disableGlobalHotkeyRegister) = keystroke(Super+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Right,disableGlobalHotkeyRegister) = keystroke(Super+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Up,disableGlobalHotkeyRegister) = keystroke(Super+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Down,disableGlobalHotkeyRegister) = keystroke(Super+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Backspace,disableGlobalHotkeyRegister) = keystroke(Super+Backspace,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Delete,disableGlobalHotkeyRegister) = keystroke(Super+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Tab,disableGlobalHotkeyRegister) = keystroke(Super+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Left,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Right,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Up,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Down,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Backspace,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Backspace,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Delete,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Control+Shift+Tab,disableGlobalHotkeyRegister) = keystroke(Super+Shift+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Left,disableGlobalHotkeyRegister) = keystroke(Alt+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Right,disableGlobalHotkeyRegister) = keystroke(Alt+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Up,disableGlobalHotkeyRegister) = keystroke(Alt+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Down,disableGlobalHotkeyRegister) = keystroke(Alt+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Delete,disableGlobalHotkeyRegister) = keystroke(Alt+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Tab,disableGlobalHotkeyRegister) = keystroke(Alt+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Left,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Right,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Up,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Down,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Backspace,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Backspace,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Delete,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Super+Shift+Tab,disableGlobalHotkeyRegister) = keystroke(Alt+Shift+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Left,disableGlobalHotkeyRegister) = keystroke(Control+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Right,disableGlobalHotkeyRegister) = keystroke(Control+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Up,disableGlobalHotkeyRegister) = keystroke(Control+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Down,disableGlobalHotkeyRegister) = keystroke(Control+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Delete,disableGlobalHotkeyRegister) = keystroke(Control+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Tab,disableGlobalHotkeyRegister) = keystroke(Control+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Left,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Left,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Right,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Right,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Up,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Up,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Down,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Down,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Backspace,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Backspace,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Delete,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Delete,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
	keystroke(Alt+Shift+Tab,disableGlobalHotkeyRegister) = keystroke(Control+Shift+Tab,Rajveer-Mac-Mini:rajveer-mp,activeScreenOnly)
end


Contributor Checklist:

  • [*] I have created a file in the doc/newsfragments directory IF it is a
    user-visible change (and make sure to read the README.md in that directory)

@axm2
Copy link

axm2 commented May 7, 2023

Hi, just found this PR and I've been using it in my workflow. Seeing as the current maintainers have moved to the input-leap fork, would you consider submitting this PR there? https://github.com/input-leap/input-leap

@Rajveer86
Copy link
Author

Hey @axm2, glad to hear you're finding this useful. I was thinking the same too as this repo doesn't look like it's maintained anymore. I'll see if I can find some time over the next couple weeks to bring this over to input leap.

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

Successfully merging this pull request may close these issues.

2 participants