From 5768a50352f2e0fc4e56b48faf09a71cc8b8e9fc Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 6 Feb 2022 15:58:03 +0000 Subject: swaybar-protocol: boxes working --- doc/quick-start.org | 229 ++++++++++++++++++++++++--------------------- src/Xmobar/Text/Swaybar.hs | 6 +- 2 files changed, 126 insertions(+), 109 deletions(-) diff --git a/doc/quick-start.org b/doc/quick-start.org index 6bd2f48..54fdcb6 100644 --- a/doc/quick-start.org +++ b/doc/quick-start.org @@ -54,162 +54,162 @@ available [[http://github.com/jaor/xmobar/raw/master/examples/xmobar.config][her #+end_src * Configuration Options *** Global options - Here are all the global configuration options that you can set within - the =Config= block in your configuration. + Here are all the global configuration options that you can set within + the =Config= block in your configuration. - - =font= Name of the font to be used. Use the =xft:= prefix for XFT - fonts. + - =font= Name of the font to be used. Use the =xft:= prefix for XFT + fonts. - - =additionalFonts= Haskell-style list of fonts to be used with the - =fn=-template. Use the =xft:= prefix for XFT fonts. See also - =textOffsets= below. For example: + - =additionalFonts= Haskell-style list of fonts to be used with the + =fn=-template. Use the =xft:= prefix for XFT fonts. See also + =textOffsets= below. For example: - #+begin_src haskell - additionalFonts = [iconFont, altIconFont] - #+end_src + #+begin_src haskell + additionalFonts = [iconFont, altIconFont] + #+end_src - - =bgColor= Background color. + - =bgColor= Background color. - - =fgColor= Default font color. + - =fgColor= Default font color. - - =alpha= The transparency. 0 is transparent, 255 is opaque. + - =alpha= The transparency. 0 is transparent, 255 is opaque. - - =position= Top, TopH, TopP, TopW, TopSize, Bottom, BottomH, - BottomP, BottomW, BottomSize or Static (with x, y, width and height). + - =position= Top, TopH, TopP, TopW, TopSize, Bottom, BottomH, + BottomP, BottomW, BottomSize or Static (with x, y, width and height). - TopP and BottomP take 2 arguments: left padding and right padding. + TopP and BottomP take 2 arguments: left padding and right padding. - TopW and BottomW take 2 arguments: an alignment parameter (L for left, - C for centered, R for Right) and an integer for the percentage width - xmobar window will have in respect to the screen width. + TopW and BottomW take 2 arguments: an alignment parameter (L for left, + C for centered, R for Right) and an integer for the percentage width + xmobar window will have in respect to the screen width. - TopSize and BottomSize take 3 arguments: an alignment parameter, an - integer for the percentage width, and an integer for the minimum pixel - height that the xmobar window will have. + TopSize and BottomSize take 3 arguments: an alignment parameter, an + integer for the percentage width, and an integer for the minimum pixel + height that the xmobar window will have. - TopH and BottomH take one argument (Int) which adjusts the bar height. + TopH and BottomH take one argument (Int) which adjusts the bar height. - For example: + For example: - #+begin_src haskell - position = TopH 30 - #+end_src + #+begin_src haskell + position = TopH 30 + #+end_src - to make a 30 tall bar on the top, or + to make a 30 tall bar on the top, or - #+begin_src haskell - position = BottomH 30 - #+end_src + #+begin_src haskell + position = BottomH 30 + #+end_src - to make a 30 tall bar on the bottom of the screen. + to make a 30 tall bar on the bottom of the screen. - #+begin_src haskell - position = BottomW C 75 - #+end_src + #+begin_src haskell + position = BottomW C 75 + #+end_src - to place xmobar at the bottom, centered with the 75% of the screen - width. Or + to place xmobar at the bottom, centered with the 75% of the screen + width. Or - #+begin_src haskell - position = BottomP 120 0 - #+end_src + #+begin_src haskell + position = BottomP 120 0 + #+end_src - to place xmobar at the bottom, with 120 pixel indent of the left. Or + to place xmobar at the bottom, with 120 pixel indent of the left. Or - #+begin_src haskell - position = Static { xpos = 0 , ypos = 0, width = 1024, height = 15 } - #+end_src + #+begin_src haskell + position = Static { xpos = 0 , ypos = 0, width = 1024, height = 15 } + #+end_src - or + or - #+begin_src haskell - position = Top - #+end_src + #+begin_src haskell + position = Top + #+end_src - - =textOffset= The vertical offset, in pixels, for the text baseline. If - negative or not given, xmobar will try to center text vertically. + - =textOffset= The vertical offset, in pixels, for the text baseline. If + negative or not given, xmobar will try to center text vertically. - - =textOffsets= A list of vertical offsets, in pixels, for the text - baseline, to be used with the each of the fonts in =additionalFonts= - (if any). If negative or not given, xmobar will try to center text - vertically for that font. + - =textOffsets= A list of vertical offsets, in pixels, for the text + baseline, to be used with the each of the fonts in =additionalFonts= + (if any). If negative or not given, xmobar will try to center text + vertically for that font. - - =iconOffset= The vertical offset, in pixels, for icons bottom line. If - negative or not given, xmobar will try to center icons vertically. + - =iconOffset= The vertical offset, in pixels, for icons bottom line. If + negative or not given, xmobar will try to center icons vertically. - - =lowerOnStart= When True the window is sent the bottom of the window - stack initially. + - =lowerOnStart= When True the window is sent the bottom of the window + stack initially. - - =hideOnStart= When set to True the window is initially not mapped, - i.e. hidden. It then can be toggled manually (for example using the - dbus interface) or automatically (by a plugin) to make it reappear. + - =hideOnStart= When set to True the window is initially not mapped, + i.e. hidden. It then can be toggled manually (for example using the + dbus interface) or automatically (by a plugin) to make it reappear. - - =allDesktops= When set to True (the default), xmobar will tell the - window manager explicitly to be shown in all desktops, by setting - =_NET_WM_DESKTOP= to 0xffffffff. + - =allDesktops= When set to True (the default), xmobar will tell the + window manager explicitly to be shown in all desktops, by setting + =_NET_WM_DESKTOP= to 0xffffffff. - - =overrideRedirect= If you're running xmobar in a tiling window - manager, you might need to set this option to =False= so that it - behaves as a docked application. Defaults to =True=. + - =overrideRedirect= If you're running xmobar in a tiling window + manager, you might need to set this option to =False= so that it + behaves as a docked application. Defaults to =True=. - - =pickBroadest= When multiple displays are available, xmobar will - choose by default the first one to place itself. With this flag set to - =True= (the default is =False=) it will choose the broadest one - instead. + - =pickBroadest= When multiple displays are available, xmobar will + choose by default the first one to place itself. With this flag set to + =True= (the default is =False=) it will choose the broadest one + instead. - - =persistent= When True the window status is fixed i.e. hiding or - revealing is not possible. This option can be toggled at runtime. - Defaults to False. + - =persistent= When True the window status is fixed i.e. hiding or + revealing is not possible. This option can be toggled at runtime. + Defaults to False. - - =border= TopB, TopBM, BottomB, BottomBM, FullB, FullBM or NoBorder - (default). + - =border= TopB, TopBM, BottomB, BottomBM, FullB, FullBM or NoBorder + (default). - TopB, BottomB, FullB take no arguments, and request drawing a border - at the top, bottom or around xmobar's window, respectively. + TopB, BottomB, FullB take no arguments, and request drawing a border + at the top, bottom or around xmobar's window, respectively. - TopBM, BottomBM, FullBM take an integer argument, which is the margin, - in pixels, between the border of the window and the drawn border. + TopBM, BottomBM, FullBM take an integer argument, which is the margin, + in pixels, between the border of the window and the drawn border. - - =borderColor= Border color. + - =borderColor= Border color. - - =borderWidth= Border width in pixels. + - =borderWidth= Border width in pixels. - - =iconRoot= Root folder where icons are stored. For == if - path start with =/=, =./= or =../= it is interpreted as it is. - Otherwise it will have + - =iconRoot= Root folder where icons are stored. For == if + path start with =/=, =./= or =../= it is interpreted as it is. + Otherwise it will have - #+begin_src haskell - iconRoot ++ "/" - #+end_src + #+begin_src haskell + iconRoot ++ "/" + #+end_src - prepended to it. Default is =.=. + prepended to it. Default is =.=. - - =commands= For setting the options of the programs to run (optional). + - =commands= For setting the options of the programs to run (optional). - - =sepChar= The character to be used for indicating commands in the - output template (default '%'). + - =sepChar= The character to be used for indicating commands in the + output template (default '%'). - - =alignSep= a 2 character string for aligning text in the output - template. The text before the first character will be align to left, - the text in between the 2 characters will be centered, and the text - after the second character will be align to the right. + - =alignSep= a 2 character string for aligning text in the output + template. The text before the first character will be align to left, + the text in between the 2 characters will be centered, and the text + after the second character will be align to the right. - - =template= The output template. + - =template= The output template. - - =wmClass= The value for the window's X11 ~WM_CLASS~ property. Defaults - to "xmobar". + - =wmClass= The value for the window's X11 ~WM_CLASS~ property. Defaults + to "xmobar". - - =wmName= The value for the window's X11 ~WM_NAME~ property. Defaults to - "xmobar". + - =wmName= The value for the window's X11 ~WM_NAME~ property. Defaults to + "xmobar". - - =textOutput= When True, instead of running as an X11 application, - write output to stdout, with optional color escape sequences. In - this mode, icon and action specifications are ignored. Default is - False. + - =textOutput= When True, instead of running as an X11 application, + write output to stdout, with optional color escape sequences. In + this mode, icon and action specifications are ignored. Default is + False. - - =textOutputFormat= Plain, Ansi or Pango, to emit, when in text - mode, escape color sequences using ANSI controls (for terminals) or - pango markup. Default is Plain. + - =textOutputFormat= Plain, Ansi or Pango, to emit, when in text + mode, escape color sequences using ANSI controls (for terminals) or + pango markup. Default is Plain. *** The output =template= @@ -314,11 +314,19 @@ available [[http://github.com/jaor/xmobar/raw/master/examples/xmobar.config][her string #+end_src + When xmobar is run in text mode with output format swaybar, box + types, colors and widths are valid too, but margins and offsets + are ignored. + ***** Bitmap Icons It's possible to insert in the global templates icon directives of the form: + prepended to it. Default is =.=. + + + #+begin_src shell #+end_src @@ -333,6 +341,8 @@ available [[http://github.com/jaor/xmobar/raw/master/examples/xmobar.config][her prepended to it. + Icons are ignored when xmobar is run in text output mode. + ***** Action Directives It's also possible to use action directives of the form: @@ -345,6 +355,9 @@ available [[http://github.com/jaor/xmobar/raw/master/examples/xmobar.config][her buttons. This tag can be nested, allowing different commands to be run depending on button clicked. + Actions work also when xmobar is run in text mode and used as + the status command of swaybar. + *** The =commands= configuration option The =commands= configuration option is a list of commands information diff --git a/src/Xmobar/Text/Swaybar.hs b/src/Xmobar/Text/Swaybar.hs index b97cc15..73ca75c 100644 --- a/src/Xmobar/Text/Swaybar.hs +++ b/src/Xmobar/Text/Swaybar.hs @@ -81,7 +81,7 @@ instance ToJSON Block where instance ToJSON Preamble withBox :: Box -> Block -> Block -withBox (Box b _ n c _) bl = +withBox (Box b _ n c _) block = (case b of BBFull -> bl { border_right = w, border_left = w , border_bottom = w, border_top = w } @@ -94,6 +94,10 @@ withBox (Box b _ n c _) bl = ) { border = bc } where w = Just (fromIntegral n) bc = if null c then Nothing else Just c + j0 = Just 0 + bl = block { border_right = j0, border_left = j0 + , border_bottom = j0, border_top = j0 } + formatSwaybar' :: Config -> Segment -> Block formatSwaybar' conf (Text txt, info, _, as) = -- cgit v1.2.3