Merge pull request #403 from elkowar/fullscreen-fix

Add new module XMonad.Util.Hacks (formerly XMonad.Hooks.WindowedFullscreenFix)
This commit is contained in:
slotThe
2021-01-07 09:22:49 +00:00
committed by GitHub
4 changed files with 84 additions and 1 deletions

View File

@@ -46,12 +46,17 @@
### New Modules
* `XMonad.Util.Hacks`
Serves as a collection of hacks and fixes that should be easily acessible to users.
The first element of this module is windowedFullscreenFix, which fixes fullscreen behaviour
of chromium based applications when using windowed fullscreen.
* `XMonad.Util.ActionCycle`
A module providing a simple way to implement "cycling" `X` actions,
useful for things like alternating toggle-style keybindings.
* `XMonad.Actions.RotateSome`
Functions for rotating some elements around the stack while keeping others

View File

@@ -1156,6 +1156,9 @@ A non complete list with a brief description:
A module for abstracting a font facility over
Core fonts and Xft.
* "XMonad.Util.Hacks":
A collection of small fixes and utilities with possibly hacky implementations.
* "XMonad.Util.Image":
Utilities for manipulating [[Bool]] as images.

74
XMonad/Util/Hacks.hs Normal file
View File

@@ -0,0 +1,74 @@
-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Util.Hacks
-- Copyright : (c) 2020 Leon Kowarschick
-- License : BSD3-style (see LICENSE)
--
-- Maintainer : Leon Kowarschick. <thereal.elkowar@gmail.com>
-- Stability : unstable
-- Portability : unportable
--
-- This module is a collection of random fixes, workarounds and other functions
-- that rely on somewhat hacky implementations which may have unwanted side effects.
--
-- Import this module as qualified like so:
--
-- > import qualified XMonad.Util.Hacks as Hacks
--
-- and then use the functions you want as described in their respective documentation.
--
-----------------------------------------------------------------------------
module XMonad.Util.Hacks
( -- * Windowed fullscreen
-- $windowedFullscreenFix
windowedFullscreenFixEventHook
) where
import XMonad
import Data.Monoid (All(All))
import Control.Monad (when)
-- $windowedFullscreenFix
-- Windowed fullscreen describes the behaviour in which XMonad,
-- by default, does not automatically put windows that request being fullscreened
-- into actual fullscreen, but keeps them constrained
-- to their normal window dimensions, still rendering them in fullscreen.
--
-- With chromium based applications like Chrome, Discord and others this
-- can cause issues, where the window does not correctly see the size of the window
-- when displaying the fullscreen content, thus cutting off the window content.
--
-- This function works around that issue by forcing the window to recalculate their
-- dimensions after initiating fullscreen, thus making chrome-based applications
-- behave properly when in windowed fullscreen.
--
-- The following gif shows the behaviour of chrome (left) without this fix
-- compared to firefox, which already behaves as expected by default:
-- <<https://user-images.githubusercontent.com/5300871/99186015-b9512500-274d-11eb-9cfc-6ba3bae6db51.gif>>
--
-- Using this function, chrome will now behave as expected as well:
-- <<https://user-images.githubusercontent.com/5300871/99186115-4dbb8780-274e-11eb-9ed2-b7815ba9e597.gif>>
--
-- Usage:
-- add to handleEventHook as follows:
--
-- > handleEventHook = handleEventHook def <+> Hacks.windowedFullscreenFixEventHook
--
-- | Fixes fullscreen behaviour of chromium based apps by quickly applying and undoing a resize.
-- This causes chromium to recalculate the fullscreen window
-- dimensions to match the actual "windowed fullscreen" dimensions.
windowedFullscreenFixEventHook :: Event -> X All
windowedFullscreenFixEventHook (ClientMessageEvent _ _ _ dpy win typ (_:dats)) = do
wmstate <- getAtom "_NET_WM_STATE"
fullscreen <- getAtom "_NET_WM_STATE_FULLSCREEN"
when (typ == wmstate && fromIntegral fullscreen `elem` dats) $ do
withWindowAttributes dpy win $ \attrs ->
liftIO $ do
resizeWindow dpy win (fromIntegral $ wa_width attrs - 1) (fromIntegral $ wa_height attrs)
resizeWindow dpy win (fromIntegral $ wa_width attrs) (fromIntegral $ wa_height attrs)
return $ All True
windowedFullscreenFixEventHook _ = return $ All True

View File

@@ -329,6 +329,7 @@ library
XMonad.Util.ExclusiveScratchpads
XMonad.Util.ExtensibleState
XMonad.Util.Font
XMonad.Util.Hacks
XMonad.Util.Image
XMonad.Util.Invisible
XMonad.Util.Loggers