-
-
Notifications
You must be signed in to change notification settings - Fork 279
X.H.Screencorners: Add per monitor hot corners #920
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
Open
Schievel1
wants to merge
1
commit into
xmonad:master
Choose a base branch
from
Schievel1:feature/monitorCorners
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
-- | | ||
-- Module : XMonad.Hooks.ScreenCorners | ||
-- Description : Run X () actions by touching the edge of your screen with your mouse. | ||
-- Copyright : (c) 2009-2025 Nils Schweinsberg, 2015 Evgeny Kurnevsky, 2024 Yuanle Song | ||
-- Copyright : (c) 2009-2025 Nils Schweinsberg, 2015 Evgeny Kurnevsky, 2024 Yuanle Song, | ||
-- 2025 Pascal Jaeger | ||
-- License : BSD3-style (see LICENSE) | ||
-- | ||
-- Maintainer : Nils Schweinsberg <[email protected]> | ||
|
@@ -21,6 +22,8 @@ module XMonad.Hooks.ScreenCorners | |
ScreenCorner (..), | ||
addScreenCorner, | ||
addScreenCorners, | ||
addMonitorCorner, | ||
addMonitorCorners, | ||
|
||
-- * Event hook | ||
screenCornerEventHook, | ||
|
@@ -35,6 +38,7 @@ import XMonad | |
import XMonad.Layout.LayoutModifier | ||
import XMonad.Prelude | ||
import qualified XMonad.Util.ExtensibleState as XS | ||
import Graphics.X11.Xinerama (xineramaQueryScreens, XineramaScreenInfo(..)) | ||
|
||
data ScreenCorner | ||
= SCUpperLeft | ||
|
@@ -51,31 +55,46 @@ data ScreenCorner | |
-- ExtensibleState modifications | ||
-------------------------------------------------------------------------------- | ||
|
||
newtype ScreenCornerState = ScreenCornerState (M.Map Window (ScreenCorner, X ())) | ||
newtype ScreenCornerState = ScreenCornerState (M.Map (ScreenCorner, Int) (Window, X ())) | ||
|
||
instance ExtensionClass ScreenCornerState where | ||
initialValue = ScreenCornerState M.empty | ||
|
||
-- | Add one single @X ()@ action to a screen corner | ||
{-# DEPRECATED addScreenCorner "addScreenCorner works only in a single monitor setup. Use addMonitorCorner instead." #-} | ||
addScreenCorner :: ScreenCorner -> X () -> X () | ||
addScreenCorner corner xF = do | ||
ScreenCornerState m <- XS.get | ||
(win, xFunc) <- case find (\(_, (sc, _)) -> sc == corner) (M.toList m) of | ||
Just (w, (_, xF')) -> return (w, xF' >> xF) -- chain X actions | ||
let key = (corner, -1) -- Use -1 to indicate a non-monitor-specific corner | ||
(win, xFunc) <- case M.lookup key m of | ||
Just (w, xF') -> return (w, xF' >> xF) -- Chain X actions | ||
Nothing -> (,xF) <$> createWindowAt corner | ||
|
||
XS.modify $ \(ScreenCornerState m') -> ScreenCornerState $ M.insert win (corner, xFunc) m' | ||
XS.modify $ \(ScreenCornerState m') -> ScreenCornerState $ M.insert key (win, xFunc) m' | ||
|
||
-- | Add a list of @(ScreenCorner, X ())@ tuples | ||
{-# DEPRECATED addScreenCorners "addScreenCorners works only in a single monitor setup. Use addMonitorCorners instead." #-} | ||
addScreenCorners :: [(ScreenCorner, X ())] -> X () | ||
addScreenCorners = mapM_ (uncurry addScreenCorner) | ||
|
||
-- | Add one single @X ()@ action to a screen corner on a specific monitor | ||
addMonitorCorner :: ScreenCorner -> Int -> Dimension -> X () -> X () | ||
addMonitorCorner corner monitorNumber hotZoneSize xF = do | ||
ScreenCornerState m <- XS.get | ||
let key = (corner, monitorNumber) | ||
(win, xFunc) <- case M.lookup key m of | ||
Just (w, xF') -> return (w, xF' >> xF) -- Chain X actions | ||
Nothing -> (,xF) <$> createWindowAtMonitor corner monitorNumber hotZoneSize | ||
XS.modify $ \(ScreenCornerState m') -> ScreenCornerState $ M.insert key (win, xFunc) m' | ||
|
||
-- | Add a list of @(ScreenCorner, Int, Dimension, X ())@ tuples | ||
addMonitorCorners :: [(ScreenCorner, Int, Dimension, X ())] -> X () | ||
addMonitorCorners = mapM_ (\(corner, monitor, hotZoneSize, xF) -> addMonitorCorner corner monitor hotZoneSize xF) | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Xlib functions | ||
-------------------------------------------------------------------------------- | ||
|
||
-- "Translate" a ScreenCorner to real (x,y) Positions with proper width and | ||
-- height. | ||
-- "Translate" a ScreenCorner to real (x,y) Positions with proper width and height. | ||
createWindowAt :: ScreenCorner -> X Window | ||
createWindowAt SCUpperLeft = createWindowAt' 0 0 1 1 | ||
createWindowAt SCUpperRight = withDisplay $ \dpy -> | ||
|
@@ -108,6 +127,30 @@ createWindowAt SCRight = withDisplay $ \dpy -> | |
threshold = 150 | ||
in createWindowAt' (fi w) threshold 1 (fi $ fi h - threshold * 2) | ||
|
||
-- "Translate" a ScreenCorner to real (x,y) Positions on a specific monitor | ||
createWindowAtMonitor :: ScreenCorner -> Int -> Dimension -> X Window | ||
createWindowAtMonitor corner monitorNumber hotZoneSize = withDisplay $ \dpy -> do | ||
screens <- io $ xineramaQueryScreens dpy | ||
case screens of | ||
Just scrs | monitorNumber < length scrs -> do | ||
let XineramaScreenInfo _ x y w h = scrs !! monitorNumber | ||
hotZoneSize' = fromIntegral hotZoneSize :: Int | ||
x' = fromIntegral x :: Int | ||
y' = fromIntegral y :: Int | ||
w' = fromIntegral w :: Int | ||
h' = fromIntegral h :: Int | ||
(xPos, yPos, width, height) = case corner of | ||
SCUpperLeft -> (x', y', hotZoneSize', hotZoneSize') | ||
SCUpperRight -> (x' + w' - hotZoneSize', y', hotZoneSize', hotZoneSize') | ||
SCLowerLeft -> (x', y' + h' - hotZoneSize', hotZoneSize', hotZoneSize') | ||
SCLowerRight -> (x' + w' - hotZoneSize', y' + h' - hotZoneSize', hotZoneSize', hotZoneSize') | ||
SCTop -> (x' + 150, y', w' - 300, hotZoneSize') | ||
SCBottom -> (x' + 150, y' + h' - hotZoneSize', w' - 300, hotZoneSize') | ||
SCLeft -> (x', y' + 150, hotZoneSize', h' - 300) | ||
SCRight -> (x' + w' - hotZoneSize', y' + 150, hotZoneSize', h' - 300) | ||
createWindowAt' (fi xPos) (fi yPos) (fi width) (fi height) | ||
_ -> error $ "Invalid monitor number or no screens available for monitorNumber=" ++ show monitorNumber | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this behavior: basically, if I unplug my monitor, and I have a configuration for two monitors, xmonad will throw an error. I suggest that the rules for non-existent monitors are simply ignored |
||
|
||
-- Create a new X window at a (x,y) Position, with given width and height. | ||
createWindowAt' :: Position -> Position -> Dimension -> Dimension -> X Window | ||
createWindowAt' x y width height = withDisplay $ \dpy -> io $ do | ||
|
@@ -117,22 +160,22 @@ createWindowAt' x y width height = withDisplay $ \dpy -> io $ do | |
attrmask = cWOverrideRedirect | ||
|
||
w <- allocaSetWindowAttributes $ \attributes -> do | ||
|
||
set_override_redirect attributes True | ||
createWindow | ||
dpy -- display | ||
rootw -- parent window | ||
x -- x | ||
y -- y | ||
width -- width | ||
height -- height | ||
0 -- border width | ||
0 -- depth | ||
inputOnly -- class | ||
visual -- visual | ||
attrmask -- valuemask | ||
attributes -- attributes | ||
|
||
-- we only need mouse entry events | ||
createWindow dpy -- display | ||
rootw -- parent window | ||
x -- x | ||
y -- y | ||
width -- width | ||
height -- height | ||
0 -- border width | ||
0 -- depth | ||
inputOnly -- class | ||
visual -- visual | ||
attrmask -- valuemask | ||
attributes -- attributes | ||
|
||
-- we only need mouse entry events selectInput dpy w enterWindowMask | ||
selectInput dpy w enterWindowMask | ||
mapWindow dpy w | ||
sync dpy False | ||
|
@@ -147,8 +190,8 @@ screenCornerEventHook :: Event -> X All | |
screenCornerEventHook CrossingEvent {ev_window = win} = do | ||
ScreenCornerState m <- XS.get | ||
|
||
case M.lookup win m of | ||
Just (_, xF) -> xF | ||
case find (\(_, (w, _)) -> w == win) (M.toList m) of | ||
Just (_, (_, xF)) -> xF | ||
Nothing -> return () | ||
|
||
return (All True) | ||
|
@@ -164,7 +207,7 @@ data ScreenCornerLayout a = ScreenCornerLayout | |
instance LayoutModifier ScreenCornerLayout a where | ||
hook ScreenCornerLayout = withDisplay $ \dpy -> do | ||
ScreenCornerState m <- XS.get | ||
io $ mapM_ (raiseWindow dpy) $ M.keys m | ||
io $ mapM_ (raiseWindow dpy . fst . snd) $ M.toList m | ||
unhook = hook | ||
|
||
screenCornerLayoutHook :: l a -> ModifiedLayout ScreenCornerLayout l a | ||
|
@@ -188,11 +231,15 @@ screenCornerLayoutHook = ModifiedLayout ScreenCornerLayout | |
-- | ||
-- > myStartupHook = do | ||
-- > ... | ||
-- > addScreenCorner SCUpperRight (goToSelected def { gs_cellwidth = 200}) | ||
-- > addScreenCorner SCBottom (goToSelected def) | ||
-- > addScreenCorners [ (SCLowerRight, nextWS) | ||
-- > , (SCLowerLeft, prevWS) | ||
-- > ] | ||
-- > addMonitorCorner SCUpperLeft 0 20 (spawn "firefox") | ||
-- > addMonitorCorner SCBottom 0 20 (spawn "firefox") | ||
-- > addMonitorCorners [ (SCUpperRight, 1, 20, spawn "xterm") | ||
-- > , (SCLowerRight, 2, 20, nextWS) | ||
-- > ] | ||
-- > ... | ||
-- | ||
-- Where 0-2 are the monitors and 20 is the size of the hot corner. | ||
-- | ||
-- | ||
-- Then add layout hook: | ||
-- | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency's sake, I think a version of this with a default size of 1 might be nice