4

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!

3 Answers3

2

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.

Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
1

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).

Jonathan Harris
  • 183
  • 1
  • 10
  • Thanks for the suggestion. This "Toggle UI" function in Vivaldi is a pretty good workaround. I only hope it can handle the full-screen button on sites like Youtube or Vimeo as well. – Kuan-Ying Chou Apr 13 '17 at 17:05
0

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

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • 1
    This setting would make XMonad behave like other desktop environments or OSes and make Chrome to fit to the entire screen, which may be what most people want. However, I'm trying to make Chrome stay in its window in full-screen mode, so that we can, say, put 2 full "screen" Youtube videos side by side in the same screen. – Kuan-Ying Chou Apr 13 '17 at 17:18
  • It's a bit of a hack but you could use something like xbindkeys and xdotool to bind F12 to (F11)+(Mod+space), so essentially automate what you're doing manually. – Chris Stryczynski Apr 13 '17 at 22:02