Kuan-Ying Chou
Kuan-Ying Chou

Reputation: 136

How to make Chrome scale correctly in full screen mode in Xmonad

When I enter full screen mode with the F11 key, or click the full screen button in Youtube or Netflix, Chrome seems to scale the page to fit the size of the screen, and the page would be cropped to its containing window. However, after toggling the layout with mod + space, it then scales to fit the containing window correctly.

How do I make Chrome's scaling to fit its window instead of the entire screen when first entering full screen mode?

I tried the functions in XMonad.Hooks.EwmhDesktops and XMonad.Layout.Fullscreen but still couldn't figure out a way.

I'm using Google Chrome 57.0.2987.98 and xmonad 0.13 on Arch. Thanks!

Upvotes: 4

Views: 1785

Answers (3)

Fresheyeball
Fresheyeball

Reputation: 30035

My solution is to use this modified version of fullscreenEventHook from EWMH.

fullscreenEventHook :: Event -> Bool -> X All
fullscreenEventHook (ClientMessageEvent _ _ _ dpy win typ (action:dats)) isChrome = do
  wmstate <- getAtom "_NET_WM_STATE"
  fullsc <- getAtom "_NET_WM_STATE_FULLSCREEN"
  wstate <- fromMaybe [] `fmap` getProp32 wmstate win

  let isFull = fromIntegral fullsc `elem` wstate

      -- Constants for the _NET_WM_STATE protocol:
      remove = 0
      add = 1
      toggle = 2
      ptype = 4 -- The atom property type for changeProperty
      chWstate f = io $ changeProperty32 dpy win wmstate ptype propModeReplace (f wstate)

      uglyChromeHack x = do
        when (not isChrome) x
        when isChrome $ windows W.swapUp >> windows W.swapDown

  when (typ == wmstate && fi fullsc `elem` dats) $ do
    when (action == add || (action == toggle && not isFull)) $ do
      chWstate (fi fullsc:)
      uglyChromeHack $ windows $ W.float win $ W.RationalRect 0 0 1 1
    when (action == remove || (action == toggle && isFull)) $ do
      chWstate $ delete (fi fullsc)
      uglyChromeHack $ windows $ W.sink win

  return $ All True

fullscreenEventHook _ _ = return $ All True


butNotChrome :: Event -> X All
butNotChrome e@(ClientMessageEvent _ _ _ _ win _ _) = do
  isChrome <- runQuery (appName =? "google-chrome") win
  fullscreenEventHook e isChrome
butNotChrome _ = return $ All True

This bit windows W.swapUp >> windows W.swapDown seems to kick chrome just hard enough.

Upvotes: 2

Chris Stryczynski
Chris Stryczynski

Reputation: 34081

You need to add the following to your config (xmonad.hs):

import XMonad.Hooks.EwmhDesktops
main = xmonad $ ewmh (yourExistingConfigValueGoesHereExample { handleEventHook =
       handleEventHook def <+> fullscreenEventHook })

More information can be found here: http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html


This functionality is also bundled into desktopConfig (a sort of sane default for xmonad). https://hackage.haskell.org/package/xmonad-contrib-0.13/docs/XMonad-Config-Desktop.html

Upvotes: 0

Jonathan Harris
Jonathan Harris

Reputation: 193

This problem has bothered me for a while too. I tried all sorts of combinations in my xmonad config file but with no luck. But I've recently found 'Vivaldi', a browser based on the Chromium engine and headed by the ex-CEO of the Opera browser. It achieves exactly what you want by using the 'Toggle UI' option (by default, Ctrl-F11).

Upvotes: 1

Related Questions