summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--changelog.md9
-rw-r--r--doc/compiling.org4
-rw-r--r--doc/quick-start.org440
-rw-r--r--doc/using-haskell.org4
-rw-r--r--readme.org69
-rw-r--r--src/Xmobar/App/Config.hs1
-rw-r--r--src/Xmobar/App/Opts.hs4
-rw-r--r--src/Xmobar/Config/Parse.hs16
-rw-r--r--src/Xmobar/Config/Template.hs188
-rw-r--r--src/Xmobar/Config/Types.hs141
-rw-r--r--src/Xmobar/Draw/Boxes.hs23
-rw-r--r--src/Xmobar/Draw/Cairo.hs48
-rw-r--r--src/Xmobar/Draw/Types.hs3
-rw-r--r--src/Xmobar/Plugins/Kraken.hs2
-rw-r--r--src/Xmobar/Plugins/Monitors/Common/Output.hs2
-rw-r--r--src/Xmobar/Run/Parsers.hs244
-rw-r--r--src/Xmobar/System/Environment.hs6
-rw-r--r--src/Xmobar/Text/Loop.hs2
-rw-r--r--src/Xmobar/Text/Output.hs24
-rw-r--r--src/Xmobar/Text/Swaybar.hs20
-rw-r--r--src/Xmobar/X11/Draw.hs5
-rw-r--r--src/Xmobar/X11/Events.hs19
-rw-r--r--src/Xmobar/X11/Loop.hs10
-rw-r--r--src/Xmobar/X11/Window.hs30
-rw-r--r--xmobar.cabal2
25 files changed, 767 insertions, 549 deletions
diff --git a/changelog.md b/changelog.md
index b4f5009..f9a3c49 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,12 @@
+## Version 0.46 (unreleased)
+
+- New bar position specifiers TopHM, BottomHM.
+- New configuration option, `dpi`, to set the font scaling factor.
+
+## Version 0.45 (October, 2022)
+
+- New cairo/pango font drawing backend, substituting the direct X11/Xft one.
+
## Version 0.44.2 (August, 2022)
- Documentation improvements.
diff --git a/doc/compiling.org b/doc/compiling.org
index 4e0125e..977ef2b 100644
--- a/doc/compiling.org
+++ b/doc/compiling.org
@@ -85,7 +85,9 @@
enters a high-CPU regime right after starting.
- =with_xrender= Enables the main bar background alpha parameter. Requires
- the [[http://hackage.haskell.org/package/X11-xft/][X11-xft]] package.
+ the [[http://hackage.haskell.org/package/X11-xft/][X11-xft]] package. The Xrender extension is not compatible with 10-bit
+ colour modes, i.e., setting ~DefaultDepth~ to 30 in your Xorg
+ configuration. See discussion in [[https://codeberg.org/xmobar/xmobar/issues/651][issue 651]] for details.
- =with_xpm= Support for xpm image file format. This will allow loading
.xpm files in =<icon>=. Requires the [[http://cgit.freedesktop.org/xorg/lib/libXpm][libXpm]] C library.
diff --git a/doc/quick-start.org b/doc/quick-start.org
index d711138..b013446 100644
--- a/doc/quick-start.org
+++ b/doc/quick-start.org
@@ -20,7 +20,7 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
This is the list of command line options (the output of =xmobar --help=):
- #+begin_src shell
+ #+begin_example
Usage: xmobar [OPTION...] [FILE]
Options:
-h, -? --help This help
@@ -38,180 +38,336 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
-o --top Place xmobar at the top of the screen
-b --bottom Place xmobar at the bottom of the screen
-d --dock Don't override redirect from WM and function as a dock
- -a alignsep --alignsep=alignsep Separators for left, center and right text
- alignment. Default: '}{'
- -s char --sepchar=char Character used to separate commands in
- the output template. Default '%'
- -t template --template=template Output template
- -c commands --commands=commands List of commands to be executed
- -C command --add-command=command Add to the list of commands to be executed
- -x screen --screen=screen On which X screen number to start
- -p position --position=position Specify position of xmobar. Same syntax as in config file
- -T [format] --text[=format] Write output to stdout
-
- Mail bug reports and suggestions to <mail@jao.io>
- #+end_src
+ -a alignsep --alignsep=alignsep Separators for left, center and right text
+ alignment. Default: '}{'
+ -s char --sepchar=char Character used to separate commands in
+ the output template. Default '%'
+ -t template --template=template Output template
+ -c commands --commands=commands List of commands to be executed
+ -C command --add-command=command Add to the list of commands to be executed
+ -x screen --screen=screen On which X screen number to start
+ -p position --position=position Specify position of xmobar. Same syntax as in config file
+ -T [format] --text[=format] Write output to stdout
+ -D dpi --dpi=dpi The DPI scaling factor. Default 96.0
+
+ Mail bug reports and suggestions to <mail@jao.io>
+ #+end_example
+
* Configuration Options
:PROPERTIES:
:CUSTOM_ID: configuration-options
:END:
** 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 options that you can set within the =Config= block in
+ your configuration and will define the overall behaviour and looks of your
+ bar.
+
+*** Fonts
+ :PROPERTIES:
+ :CUSTOM_ID: fonts
+ :END:
+
+ The following configuration options control the fonts used by xmobar:
+
+ - =font= Name, as a string, of the default font to use.
- - =font= Name of the font to be used.
+ - =additionalFonts= Haskell-style list of fonts to us with the
+ =fn=-template. See also =textOffsets= below. For example:
- - =additionalFonts= Haskell-style list of fonts to be used with the
- =fn=-template. See also =textOffsets= below. For example:
+ #+begin_src haskell
+ additionalFonts = [iconFont, altIconFont]
+ #+end_src
+
+ - =dpi= The DPI scaling factor, as a decimal, to use. If 0, negative, or not
+ given, the default of 96 will be used, which corresponds to an average
+ screen. A 10pt font will therefore scale to 10pt * (1/72 pt/inch) * (96
+ pixel/inch) = 13.3 pixel. This is especially useful for HiDPI displays.
+
+ The global font is used by default when none of the others is specified
+ using the ~<fn=n>...</fn>~ markup, with ~n~ a 1-based index in the
+ ~additionalFonts~ array. So, for instance
+
+ #+begin_src
+ <fn=2>some text</fn>
+ #+end_src
+
+ will use, in the configuration above, ~altIconFont~ to display "some text".
- #+begin_src haskell
- additionalFonts = [iconFont, altIconFont]
- #+end_src
+ Font names use the [[https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html][Pango format]]. Here are a few simple examples:
- - =bgColor= Background color.
+ #+begin_example
+ DejaVu Sans Mono 10
- - =fgColor= Default font color.
+ Iosevka Comfy Semi-Bold Italic 12
- - =alpha= The transparency. 0 is transparent, 255 is opaque.
+ Noto Color Emoji 10
+ #+end_example
- - =position= Top, TopH, TopP, TopW, TopSize, Bottom, BottomH,
- BottomP, BottomW, BottomSize or Static (with x, y, width and height).
+ We start with a family name (DejaVu Sans Mono, Iosevka Comfy, etc.),
+ followed by optional, space-separated /style options/ (Semi-Bold Italic in
+ the second example above), and ending with a size, in points.
- TopP and BottomP take 2 arguments: left padding and right padding.
+ There are many possible style options (if your font supports them). They
+ can be
- 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.
+ - *Plain styles*: Normal, Roman, Oblique, Italic.
+ - *Variants*: Small-Caps, All-Small-Caps, Petite-Caps, All-Petite-Caps,
+ Unicase, Title-Caps.
+ - *Weights*: Thin, Ultra-Light, Extra-Light, Light, Semi-Ligh, Demi-Light,
+ Book, Regular, Medium, Semi-Bold, Demi-Bold, Bold, Ultra-Bold,
+ Extra-Bold, Heavy, Black, Ultra-Black, Extra-Black.
+ - *Strectch values:* Thin, Ultra-Light, Extra-Light, Light, Semi-Light,
+ Demi-Light, Book, Regular, Medium, Semi-Bold, Demi-Bold, Bold,
+ Ultra-Bold, Extra-Bold, Heavy, Black, Ultra-Black, Extra-Black.
+ - *Gravity values*: Not-Rotated, South, Upside-Down, North, Rotated-Left,
+ East, Rotated-Right, West.
- 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.
+ So you can add up to 5 style options per family:
- TopH and BottomH take one argument (Int) which adjusts the bar height.
+ #+begin_example
+ Monospace Italic All-Small-Caps Extra-Light Thin North 12
+ #+end_example
- For example:
+ It's also possible to specify a list of fonts, separating them by commas,
+ so that they act as fallbacks when the preceding one is not able to display
+ a given glyph. A bit confusingly, the styles and sizes come in reverse
+ order after the families:
- #+begin_src haskell
- position = TopH 30
- #+end_src
+ #+begin_example
+ Family 1, Family 2 Styles 2 Size 2, Styles 1 Size 1
+ #+end_example
- to make a 30 tall bar on the top, or
+ For instance you could have:
- #+begin_src haskell
- position = BottomH 30
- #+end_src
+ #+begin_example
+ Souce Code Pro, Noto Color Emoji Regular 12, Semi-Bold 10
+ #+end_example
- to make a 30 tall bar on the bottom of the screen.
+ to use Source Code Pro Semi-Bold 10 when possible, and fall back to Noto
+ Color Emoji Regular 12 for characters that the former cannot display.
- #+begin_src haskell
- position = BottomW C 75
- #+end_src
+*** Colors
- to place xmobar at the bottom, centered with the 75% of the screen
- width. Or
+ - =bgColor= Background color.
- #+begin_src haskell
- position = BottomP 120 0
- #+end_src
+ - =fgColor= Default font color.
- to place xmobar at the bottom, with 120 pixel indent of the left. Or
+ - =alpha= The transparency. 0 is transparent, 255 is opaque.
- #+begin_src haskell
- position = Static { xpos = 0 , ypos = 0, width = 1024, height = 15 }
- #+end_src
+*** Vertical offsets
- or
+ By default, all text and icons in the bar will be vertically centered
+ according to the configured height of the bar. You can override that
+ behaviour with the following options:
- #+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.
+*** Borders
- - =lowerOnStart= When True the window is sent the bottom of the window
- stack initially.
+ - =border= TopB, TopBM, BottomB, BottomBM, FullB, FullBM or NoBorder
+ (default).
- - =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.
+ TopB, BottomB, FullB take no arguments, and request drawing a border
+ at the top, bottom or around xmobar's window, respectively.
- - =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.
+ TopBM, BottomBM, FullBM take an integer argument, which is the margin,
+ in pixels, between the border of the window and the drawn border.
- - =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=.
+ - =borderColor= Border color.
- - =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.
+ - =borderWidth= Border width in pixels.
- - =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.
+ - =iconRoot= Root folder where icons are stored. For =<icon=path/>= if
+ path start with =/=, =./= or =../= it is interpreted as it is.
+ Otherwise it will have
+
+ #+begin_src haskell
+ iconRoot ++ "/"
+ #+end_src
- - =border= TopB, TopBM, BottomB, BottomBM, FullB, FullBM or NoBorder
- (default).
+ prepended to it. Default is =.=.
- TopB, BottomB, FullB take no arguments, and request drawing a border
- at the top, bottom or around xmobar's window, respectively.
+*** Bar position
- TopBM, BottomBM, FullBM take an integer argument, which is the margin,
- in pixels, between the border of the window and the drawn border.
+ - =position= Top, TopH, TopHM, TopP, TopW, TopSize, Bottom, BottomH, BottomHM,
+ BottomP, BottomW, BottomSize or Static (with x, y, width and height).
- - =borderColor= Border color.
+ TopP and BottomP take 2 arguments: left padding and right padding.
- - =borderWidth= Border width in pixels.
+ 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.
- - =iconRoot= Root folder where icons are stored. For =<icon=path/>= if
- path start with =/=, =./= or =../= it is interpreted as it is.
- Otherwise it 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.
- #+begin_src haskell
- iconRoot ++ "/"
- #+end_src
+ TopH and BottomH take one argument (Int) which adjusts the bar height.
+
+ For example:
+
+ #+begin_src haskell
+ position = TopH 30
+ #+end_src
+
+ to make a 30 tall bar on the top, or
+
+ #+begin_src haskell
+ position = BottomH 30
+ #+end_src
+
+ to make a 30 tall bar on the bottom of the screen. The corresponding
+ variants ~TopHM~ and ~BottomHM~ allow you to specify, in addition to a
+ height, margins (in pixels) with the borders of the screen (left, right
+ top and bottom); so they take five integers as arguments. For instance,
+ if you one a margin of 2 pixels to the left of the top bar in the above
+ example and 4 to its right and top, you could use:
+
+ #+begin_src haskell
+ position = TopHM 30 2 4 4 0
+ #+end_src
+
+ and similarly for ~BottomHM~.
+
+ #+begin_src haskell
+ position = BottomW C 75
+ #+end_src
+
+ to place xmobar at the bottom, centered with the 75% of the screen
+ width. Or
+
+ #+begin_src haskell
+ position = BottomP 120 0
+ #+end_src
+
+ 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
+
+ or
+
+ #+begin_src haskell
+ position = Top
+ #+end_src
+
+ - =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.
+
+ - =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=.
+
+ - =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.
+
+ - =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".
+
+*** Text output
+
+ - =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.
+
+*** Commands and monitors
+
+ - =commands= The list of monitors and plugins to run, together with their
+ individual configurations. The [[./plugins.org][plugin documentation]] details all the
+ available monitors, and you can also create new ones using Haskell. See
+ [[#commands-list][The commands list]] section below for more.
+
+ - =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.
+
+ - =template= The output template: a string telling xmobar how to display the
+ outputs of all the =commands= above. See [[#output-template][the next section]] for a full
+ description.
+
+** The =commands= list
+ :PROPERTIES:
+ :CUSTOM_ID: commands-list
+ :END:
+
+ The =commands= configuration option is a list of commands information
+ and arguments to be used by xmobar when parsing the output template.
+ Each member of the list consists in a command prefixed by the =Run=
+ keyword. Each command has arguments to control the way xmobar is going
+ to execute it.
- prepended to it. Default is =.=.
+ The options consist in a list of commands separated by a comma and enclosed
+ by square parenthesis.
- - =commands= For setting the options of the programs to run (optional).
+ Example:
- - =sepChar= The character to be used for indicating commands in the
- output template (default '%').
+ #+begin_src haskell
+ [Run Memory ["-t","Mem: <usedratio>%"] 10, Run Swap [] 10]
+ #+end_src
- - =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.
+ to run the Memory monitor plugin with the specified template, and the
+ swap monitor plugin, with default options, every second. And here's an
+ example of a template for the commands above using an icon:
- - =template= The output template.
+ #+begin_src haskell
+ template = "<icon=/home/jao/.xmobar/mem.xbm/><memory> <swap>"
+ #+end_src
- - =wmClass= The value for the window's X11 ~WM_CLASS~ property. Defaults
- to "xmobar".
+ This example will run "xclock" command when date is clicked:
- - =wmName= The value for the window's X11 ~WM_NAME~ property. Defaults to
- "xmobar".
+ #+begin_src haskell
+ template = "<action=`xclock`>%date%</action>"
+ #+end_src
- - =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.
+ The only internal available command is =Com= (see below Executing
+ External Commands). All other commands are provided by plugins. xmobar
+ comes with some plugins, providing a set of system monitors, a standard
+ input reader, an Unix named pipe reader, a configurable date plugin, and
+ much more: we list all available plugins below.
- - =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.
+ Other commands can be created as plugins with the Plugin infrastructure.
+ See below.
** The output =template=
+ :PROPERTIES:
+ :CUSTOM_ID: output-template
+ :END:
The output template is how xmobar will end up printing all of your
configured commands. It must contain at least one command. Xmobar
@@ -319,7 +475,7 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
types, colors and widths are valid too, but margins and offsets
are ignored.
-*** Bitmap Icons
+*** Bitmap icons
It's possible to insert in the global templates icon directives of the
form:
@@ -344,7 +500,7 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
Icons are ignored when xmobar is run in text output mode.
-*** Action Directives
+*** Using the mouse: Action directives
It's also possible to use action directives of the form:
@@ -359,46 +515,6 @@ configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you
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
- and arguments to be used by xmobar when parsing the output template.
- Each member of the list consists in a command prefixed by the =Run=
- keyword. Each command has arguments to control the way xmobar is going
- to execute it.
-
- The option consists in a list of commands separated by a comma and
- enclosed by square parenthesis.
-
- Example:
-
- #+begin_src haskell
- [Run Memory ["-t","Mem: <usedratio>%"] 10, Run Swap [] 10]
- #+end_src
-
- to run the Memory monitor plugin with the specified template, and the
- swap monitor plugin, with default options, every second. And here's an
- example of a template for the commands above using an icon:
-
- #+begin_src haskell
- template = "<icon=/home/jao/.xmobar/mem.xbm/><memory> <swap>"
- #+end_src
-
- This example will run "xclock" command when date is clicked:
-
- #+begin_src haskell
- template = "<action=`xclock`>%date%</action>"
- #+end_src
-
- The only internal available command is =Com= (see below Executing
- External Commands). All other commands are provided by plugins. xmobar
- comes with some plugins, providing a set of system monitors, a standard
- input reader, an Unix named pipe reader, a configurable date plugin, and
- much more: we list all available plugins below.
-
- Other commands can be created as plugins with the Plugin infrastructure.
- See below.
-
* Runtime behaviour
** Running xmobar in text mode
:PROPERTIES:
diff --git a/doc/using-haskell.org b/doc/using-haskell.org
index 4020557..33228c7 100644
--- a/doc/using-haskell.org
+++ b/doc/using-haskell.org
@@ -26,7 +26,7 @@
config :: Config
config =
defaultConfig
- { font = "xft:Terminus-8",
+ { font = "DejaVu Sans Mono 9",
allDesktops = True,
alpha = 200,
commands =
@@ -40,7 +40,7 @@
}
main :: IO ()
- main = xmobar config
+ main = xmobar config -- or: configFromArgs config >>= xmobar
#+end_src
You can then for instance run =ghc --make xmobar.hs= to create a new xmobar
diff --git a/readme.org b/readme.org
index f9226e9..43a973f 100644
--- a/readme.org
+++ b/readme.org
@@ -29,6 +29,17 @@ output, in a variety of formats.
Check [[./changelog.md][the change log]] for our release history. We also have an IRC
channel, ~#xmobar~, at [[ircs://irc.libera.chat][Libera]].
+* Breaking news
+
+ - Starting with version 0.45 we use cairo/pango as our drawing engine
+ (instead of plain X11/Xft). From a user's point of view, that change
+ should be mostly transparent, except for the facts that it's allowed
+ fixing quite a few bugs and that your /font names/ in your configuration, if
+ you used ~xft~ ones, might need to be adapted to Pango's syntax: please see
+ [[./doc/quick-start.org#fonts][this section of the documentation]] for all the details. If you're
+ compiling your own xmobar, there's a new dependency on libpango (see
+ [[./doc/compiling.org#c-libraries][C library dependencies]]).
+
* Installation
:PROPERTIES:
:CUSTOM_ID: installation
@@ -145,36 +156,34 @@ channel, ~#xmobar~, at [[ircs://irc.libera.chat][Libera]].
* Authors and credits
- Andrea Rossato originally designed and implemented xmobar up to
- version 0.11.1. Since then, it is maintained and developed by [[https://jao.io][jao]],
- with the help of the greater xmobar and Haskell communities.
-
- In particular, xmobar incorporates patches by Mohammed Alshiekh,
- Alex Ameen, Axel Angel, Dhananjay Balan, Claudio Bley, Dragos Boca,
- Ben Boeckel, Ivan Brennan, Duncan Burke, Roman Cheplyaka, Patrick
- Chilton, Antoine Eiche, Nathaniel Wesley Filardo, Guy Gastineau,
- John Goerzen, Patrick Günther, Reto Hablützel, Juraj Hercek, Tomáš
- Janoušek, Ada Joule, Spencer Janssen, Roman Joost, Pavel Kalugin,
- Jochen Keil, Sam Kirby, Lennart Kolmodin, Krzysztof Kosciuszkiewicz,
- Dmitry Kurochkin, Todd Lunter, Vanessa McHale, Robert J. Macomber,
- Dmitry Malikov, David McLean, Joan MIlev, Marcin Mikołajczyk, Dino
- Morelli, Tony Morris, Eric Mrak, Thiago Negri, Edward O'Callaghan,
- Svein Ove, Martin Perner, Jens Petersen, Alexander Polakov, Sibi
- Prabakaran, Pavan Rikhi, Petr Rockai, Andrew Emmanuel Rosa,
- Sackville-West, Amir Saeid, Markus Scherer, Daniel Schüssler,
- Olivier Schneider, Alexander Shabalin, Valentin Shirokov, Peter
- Simons, Alexander Solovyov, Will Song, John Soo, John Soros, Felix
- Springer, Travis Staton, Artem Tarasov, Samuli Thomasson, Edward
- Tjörnhammar, Sergei Trofimovich, Thomas Tuegel, John Tyree, Jan
- Vornberger, Anton Vorontsov, Daniel Wagner, Zev Weiss, Phil Xiaojun
- Hu, Nikolay Yakimov, Edward Z. Yang, Leo Zhang, Norbert Zeh, and
- Michał Zielonka.
-
- Andrea wants to thank Robert Manea and Spencer Janssen for their
- help in understanding how X works. They gave him suggestions on how
- to solve many problems with xmobar. He also thanks Claus Reinke for
- making him understand existential types (or at least for letting him
- think he grasps existential types...;-).
+ Andrea Rossato originally designed and implemented xmobar up to version
+ 0.11.1. Since then, it is maintained and developed by [[https://jao.io][jao]], with the help of
+ the greater xmobar and Haskell communities.
+
+ In particular, xmobar incorporates patches by Kostas Agnantis, Mohammed
+ Alshiekh, Alex Ameen, Axel Angel, Dhananjay Balan, Claudio Bley, Dragos
+ Boca, Ben Boeckel, Ivan Brennan, Duncan Burke, Roman Cheplyaka, Patrick
+ Chilton, Antoine Eiche, Nathaniel Wesley Filardo, Guy Gastineau, John
+ Goerzen, Jonathan Grochowski, Patrick Günther, Reto Hablützel, Juraj Hercek,
+ Tomáš Janoušek, Ada Joule, Spencer Janssen, Roman Joost, Pavel Kalugin,
+ Jochen Keil, Sam Kirby, Lennart Kolmodin, Krzysztof Kosciuszkiewicz, Dmitry
+ Kurochkin, Todd Lunter, Vanessa McHale, Robert J. Macomber, Dmitry Malikov,
+ David McLean, Joan Milev, Marcin Mikołajczyk, Dino Morelli, Tony Morris,
+ Eric Mrak, Thiago Negri, Edward O'Callaghan, Svein Ove, Martin Perner, Jens
+ Petersen, Alexander Polakov, Sibi Prabakaran, Pavan Rikhi, Petr Rockai,
+ Andrew Emmanuel Rosa, Sackville-West, Amir Saeid, Markus Scherer, Daniel
+ Schüssler, Olivier Schneider, Alexander Shabalin, Valentin Shirokov, Peter
+ Simons, Alexander Solovyov, Will Song, John Soo, John Soros, Felix Springer,
+ Travis Staton, Artem Tarasov, Samuli Thomasson, Edward Tjörnhammar, Sergei
+ Trofimovich, Thomas Tuegel, John Tyree, Jan Vornberger, Anton Vorontsov,
+ Daniel Wagner, Zev Weiss, Phil Xiaojun Hu, Nikolay Yakimov, Edward Z. Yang,
+ Leo Zhang, Norbert Zeh, and Michał Zielonka.
+
+ Andrea wants to thank Robert Manea and Spencer Janssen for their help in
+ understanding how X works. They gave him suggestions on how to solve many
+ problems with xmobar. He also thanks Claus Reinke for making him understand
+ existential types (or at least for letting him think he grasps existential
+ types...;-).
* License
diff --git a/src/Xmobar/App/Config.hs b/src/Xmobar/App/Config.hs
index a284973..5c2f362 100644
--- a/src/Xmobar/App/Config.hs
+++ b/src/Xmobar/App/Config.hs
@@ -67,6 +67,7 @@ defaultConfig =
, signal = SignalChan Nothing
, textOutput = False
, textOutputFormat = Plain
+ , dpi = 96.0
}
-- | Return the path to the xmobar data directory. This directory is
diff --git a/src/Xmobar/App/Opts.hs b/src/Xmobar/App/Opts.hs
index 3a6b4e7..bc01435 100644
--- a/src/Xmobar/App/Opts.hs
+++ b/src/Xmobar/App/Opts.hs
@@ -52,6 +52,7 @@ data Opts = Help
| Position String
| WmClass String
| WmName String
+ | Dpi String
deriving (Show, Eq)
options :: [OptDescr Opts]
@@ -95,6 +96,8 @@ options =
"On which X screen number to start"
, Option "p" ["position"] (ReqArg Position "position")
"Specify position of xmobar. Same syntax as in config file"
+ , Option "D" ["dpi"] (ReqArg Dpi "dpi")
+ "The DPI scaling factor. Default 96.0"
]
getOpts :: [String] -> IO ([Opts], [String])
@@ -161,6 +164,7 @@ doOpts conf (o:oo) =
Right x -> doOpts' (conf {commands = commands conf ++ x})
Left e -> putStr (e ++ usage) >> exitWith (ExitFailure 1)
Position s -> readPosition s
+ Dpi d -> doOpts' (conf {dpi = read d})
where readCom c str =
case readStr str of
[x] -> Right x
diff --git a/src/Xmobar/Config/Parse.hs b/src/Xmobar/Config/Parse.hs
index 16af3db..0b41267 100644
--- a/src/Xmobar/Config/Parse.hs
+++ b/src/Xmobar/Config/Parse.hs
@@ -19,7 +19,8 @@
module Xmobar.Config.Parse(readConfig
, parseConfig
, indexedFont
- , indexedOffset) where
+ , indexedOffset
+ , colorComponents) where
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Number (int)
@@ -31,6 +32,14 @@ import Xmobar.Config.Types
import qualified System.IO as S (readFile)
+-- | Splits a colors string into its two components
+colorComponents :: Config -> String -> (String, String)
+colorComponents conf c =
+ case break (==',') c of
+ (f,',':b) -> (f, b)
+ (f, _) -> (f, bgColor conf)
+
+
stripComments :: String -> String
stripComments =
unlines . map (drop 5 . strip False . (replicate 5 ' '++)) . lines
@@ -63,7 +72,7 @@ parseConfig defaultConfig =
<|?> pAllDesktops <|?> pOverrideRedirect <|?> pPickBroadest
<|?> pLowerOnStart <|?> pPersistent <|?> pIconRoot
<|?> pCommands <|?> pSepChar <|?> pAlignSep <|?> pTemplate
- <|?> pVerbose <|?> pSignal
+ <|?> pVerbose <|?> pSignal <|?> pDpi
fields = [ "font", "additionalFonts", "bgColor", "fgColor"
, "wmClass", "wmName", "sepChar"
@@ -72,7 +81,7 @@ parseConfig defaultConfig =
, "allDesktops", "overrideRedirect", "pickBroadest"
, "hideOnStart", "lowerOnStart", "persistent", "iconRoot"
, "alpha", "commands", "verbose", "signal", "textOutput"
- , "textOutputFormat"
+ , "textOutputFormat", "dpi"
]
pTextOutput = readField textOutput "textOutput"
@@ -103,6 +112,7 @@ parseConfig defaultConfig =
pIconRoot = readField iconRoot "iconRoot"
pAlpha = readField alpha "alpha"
pVerbose = readField verbose "verbose"
+ pDpi = readField dpi "dpi"
pSignal = field signal "signal" $
fail "signal is meant for use with Xmobar as a library.\n It is not meant for use in the configuration file."
diff --git a/src/Xmobar/Config/Template.hs b/src/Xmobar/Config/Template.hs
new file mode 100644
index 0000000..ad30c3d
--- /dev/null
+++ b/src/Xmobar/Config/Template.hs
@@ -0,0 +1,188 @@
+------------------------------------------------------------------------------
+-- |
+-- Module: Xmobar.Config.Template
+-- Copyright: (c) 2022 jao
+-- License: BSD3-style (see LICENSE)
+--
+-- Maintainer: mail@jao.io
+-- Stability: unstable
+-- Portability: portable
+-- Created: Fri Sep 30, 2022 06:33
+--
+--
+-- Parsing template strings
+--
+------------------------------------------------------------------------------
+
+
+module Xmobar.Config.Template (parseString) where
+
+import Data.Maybe (fromMaybe)
+import qualified Control.Monad as CM
+
+import Text.Parsec ((<|>))
+import Text.Read (readMaybe)
+
+import qualified Text.Parsec as P
+import qualified Text.Parsec.Combinator as C
+
+import Text.ParserCombinators.Parsec (Parser)
+
+import qualified Xmobar.Config.Types as T
+
+type Context = (T.TextRenderInfo, T.FontIndex, Maybe [T.Action])
+
+retSegment :: Context -> T.Widget -> Parser [T.Segment]
+retSegment (i, idx, as) widget = return [(widget, i, idx, as)]
+
+-- | Run the template string parser for the given config, producing a list of
+-- drawable segment specifications.
+parseString :: T.Config -> String -> [T.Segment]
+parseString c s =
+ case P.parse (stringParser ci) "" s of
+ Left _ -> [(T.Text $ "Could not parse string: " ++ s, ti, 0, Nothing)]
+ Right x -> concat x
+ where ci = (ti , 0, Nothing)
+ ti = T.TextRenderInfo (T.fgColor c) 0 0 []
+
+-- Top level parser reading the full template string
+stringParser :: Context -> Parser [[T.Segment]]
+stringParser c = C.manyTill (allParsers c) C.eof
+
+allParsers :: Context -> Parser [T.Segment]
+allParsers c = C.choice (textParser c:map (\f -> P.try (f c)) parsers)
+ where parsers = [ iconParser, hspaceParser, rawParser, actionParser
+ , fontParser, boxParser, colorParser ]
+
+-- Wrapper for notFollowedBy that returns the result of the first parser.
+-- Also works around the issue that, at least in Parsec 3.0.0, notFollowedBy
+-- accepts only parsers with return type Char.
+notFollowedBy' :: Parser a -> Parser b -> Parser a
+notFollowedBy' p e = do x <- p
+ C.notFollowedBy $ P.try (e >> return '*')
+ return x
+
+-- Parse a maximal string without markup
+textParser :: Context -> Parser [T.Segment]
+textParser c =
+ C.many1 (P.noneOf "<" <|> P.try (notFollowedBy' (P.char '<') suffixes))
+ >>= retSegment c . T.Text
+ where suffixes = C.choice $ map (P.try . P.string)
+ [ "icon=" , "hspace=", "raw="
+ , "action=", "/action>", "fn=", "/fn>"
+ , "box", "/box>", "fc=", "/fc>" ]
+
+-- Parse a "raw" tag, which we use to prevent other tags from creeping in.
+-- The format here is net-string-esque: a literal "<raw=" followed by a string
+-- of digits (base 10) denoting the length of the raw string, a literal ":" as
+-- digit-string-terminator, the raw string itself, and then a literal "/>".
+rawParser :: Context -> Parser [T.Segment]
+rawParser c = do
+ P.string "<raw="
+ lenstr <- C.many1 P.digit
+ P.char ':'
+ case reads lenstr of
+ [(len,[])] -> do
+ CM.guard ((len :: Integer) <= fromIntegral (maxBound :: Int))
+ s <- C.count (fromIntegral len) P.anyChar
+ P.string "/>"
+ retSegment c (T.Text s)
+ _ -> CM.mzero
+
+iconParser :: Context -> Parser [T.Segment]
+iconParser c = do
+ P.string "<icon="
+ i <- C.manyTill (P.noneOf ">") (P.try (P.string "/>"))
+ retSegment c (T.Icon i)
+
+hspaceParser :: Context -> Parser [T.Segment]
+hspaceParser c = do
+ P.string "<hspace="
+ pVal <- C.manyTill P.digit (P.try (P.string "/>"))
+ retSegment c (T.Hspace (fromMaybe 0 $ readMaybe pVal))
+
+actionParser :: Context -> Parser [T.Segment]
+actionParser (ti, fi, act) = do
+ P.string "<action="
+ command <- C.between (P.char '`') (P.char '`') (C.many1 (P.noneOf "`"))
+ <|> C.many1 (P.noneOf ">")
+ buttons <- (P.char '>' >> return "1") <|> (P.space >> P.spaces >>
+ C.between (P.string "button=") (P.string ">") (C.many1 (P.oneOf "12345")))
+ let a = T.Spawn (toButtons buttons) command
+ a' = case act of
+ Nothing -> Just [a]
+ Just act' -> Just $ a : act'
+ s <- C.manyTill (allParsers (ti, fi, a')) (P.try $ P.string "</action>")
+ return (concat s)
+
+toButtons :: String -> [T.Button]
+toButtons = map (\x -> read [x])
+
+colorParser :: Context -> Parser [T.Segment]
+colorParser (T.TextRenderInfo _ _ _ bs, fidx, a) = do
+ c <- C.between (P.string "<fc=") (P.string ">") (C.many1 colorc)
+ let colorParts = break (==':') c
+ let (ot,ob) = case break (==',') (drop 1 $ snd colorParts) of
+ (top,',':btm) -> (top, btm)
+ (top, _) -> (top, top)
+ tri = T.TextRenderInfo (fst colorParts)
+ (fromMaybe (-1) $ readMaybe ot)
+ (fromMaybe (-1) $ readMaybe ob)
+ bs
+ s <- C.manyTill (allParsers (tri, fidx, a)) (P.try $ P.string "</fc>")
+ return (concat s)
+ where colorc = P.alphaNum <|> P.oneOf ",:#"
+
+boxParser :: Context -> Parser [T.Segment]
+boxParser (T.TextRenderInfo cs ot ob bs, f, a) = do
+ c <- C.between (P.string "<box") (P.string ">")
+ (C.option "" (C.many1 (P.alphaNum <|> P.oneOf "= #,")))
+ let b = T.Box T.BBFull (T.BoxOffset T.C 0) 1 cs (T.BoxMargins 0 0 0 0)
+ let g = boxReader b (words c)
+ s <- C.manyTill
+ (allParsers (T.TextRenderInfo cs ot ob (g : bs), f, a))
+ (P.try $ P.string "</box>")
+ return (concat s)
+
+boxReader :: T.Box -> [String] -> T.Box
+boxReader b [] = b
+boxReader b (x:xs) = boxReader (boxParamReader b param val) xs
+ where (param,val) = case break (=='=') x of
+ (p,'=':v) -> (p, v)
+ (p, _) -> (p, "")
+
+boxParamReader :: T.Box -> String -> String -> T.Box
+boxParamReader b _ "" = b
+
+boxParamReader (T.Box bb off lw fc mgs) "type" val =
+ T.Box (fromMaybe bb $ readMaybe ("BB" ++ val)) off lw fc mgs
+
+boxParamReader (T.Box bb (T.BoxOffset alg off) lw fc mgs) "offset" (a:o) =
+ T.Box bb (T.BoxOffset align offset) lw fc mgs
+ where offset = fromMaybe off $ readMaybe o
+ align = fromMaybe alg $ readMaybe [a]
+
+boxParamReader (T.Box bb off lw fc mgs) "width" val =
+ T.Box bb off (fromMaybe lw $ readMaybe val) fc mgs
+
+boxParamReader (T.Box bb off lw _ mgs) "color" val =
+ T.Box bb off lw val mgs
+
+boxParamReader (T.Box bb off lw fc mgs@(T.BoxMargins mt mr mb ml)) ('m':pos) v =
+ let mgs' = case pos of
+ "t" -> T.BoxMargins (maybeVal mt) mr mb ml
+ "r" -> T.BoxMargins mt (maybeVal mr) mb ml
+ "b" -> T.BoxMargins mt mr (maybeVal mb) ml
+ "l" -> T.BoxMargins mt mr mb (maybeVal ml)
+ _ -> mgs
+ maybeVal d = fromMaybe d (readMaybe v)
+ in T.Box bb off lw fc mgs'
+
+boxParamReader b _ _ = b
+
+fontParser :: Context -> Parser [T.Segment]
+fontParser (i, _, a) = do
+ f <- C.between (P.string "<fn=") (P.string ">") (C.many1 P.digit)
+ s <- C.manyTill (allParsers (i, fromMaybe 0 $ readMaybe f, a))
+ (P.try $ P.string "</fn>")
+ return (concat s)
diff --git a/src/Xmobar/Config/Types.hs b/src/Xmobar/Config/Types.hs
index 4959aa1..785b55b 100644
--- a/src/Xmobar/Config/Types.hs
+++ b/src/Xmobar/Config/Types.hs
@@ -15,14 +15,28 @@
module Xmobar.Config.Types
( Config (..)
, XPosition (..), Align (..), Border (..), TextOutputFormat (..)
+ , Segment
, FontIndex
+ , Box(..)
+ , BoxBorder(..)
+ , BoxOffset(..)
+ , BoxMargins(..)
+ , TextRenderInfo(..)
+ , Widget(..)
, SignalChan (..)
+ , Action (..)
+ , Button
) where
import qualified Control.Concurrent.STM as STM
import qualified Xmobar.Run.Runnable as R
import qualified Xmobar.System.Signal as S
+import Data.Int (Int32)
+import Foreign.C.Types (CInt)
+
+import Xmobar.Run.Actions (Action (..), Button)
+
-- $config
-- Configuration data type
@@ -71,20 +85,94 @@ data Config =
, template :: String -- ^ The output template
, verbose :: Bool -- ^ Emit additional debug messages
, signal :: SignalChan -- ^ Channel to send signals to xmobar
+ , dpi :: Double -- ^ DPI scaling factor for fonts
} deriving (Read, Show)
-data XPosition = Top
- | TopH Int
- | TopW Align Int
- | TopSize Align Int Int
- | TopP Int Int
+-- | The position datatype
+data XPosition = Top -- ^ Top of the screen, full width, auto height
+
+ | TopH -- ^ Top of the screen, full width with
+ -- specific height
+ Int -- ^ Height (in pixels)
+
+ -- | Top of the screen, full width with
+ -- specific height and margins
+ | TopHM
+ Int -- ^ Height (in pixels)
+ Int -- ^ Left margin (in pixels)
+ Int -- ^ Right margin (in pixels)
+ Int -- ^ Top margin (in pixels)
+ Int -- ^ Bottom margin (in pixels)
+
+ -- | Top of the screen with specific width
+ -- (as screen percentage) and alignment
+ | TopW
+ Align -- ^ Alignement (L|C|R)
+ Int -- ^ Width as screen percentage (0-100)
+
+ -- | Top of the screen with specific width
+ -- (as screen percentage), height and
+ -- alignment
+ | TopSize
+ Align -- ^ Alignement (L|C|R)
+ Int -- ^ Width as screen percentage (0-100)
+ Int -- ^ Height (in pixels)
+
+ -- | Top of the screen with specific left/right
+ -- margins
+ | TopP
+ Int -- ^ Left margin (in pixels)
+ Int -- ^ Right margin (in pixels)
+
+ -- | Bottom of the screen, full width, auto height
| Bottom
- | BottomH Int
- | BottomP Int Int
- | BottomW Align Int
- | BottomSize Align Int Int
- | Static {xpos, ypos, width, height :: Int}
- | OnScreen Int XPosition
+
+ | BottomH -- ^ Bottom of the screen, full width, with
+ -- specific height
+ Int -- ^ Height (in pixels)
+
+ -- | Bottom of the screen with specific height
+ -- and margins
+ | BottomHM
+ Int -- ^ Height (in pixels)
+ Int -- ^ Left margin (in pixels)
+ Int -- ^ Right margin (in pixels)
+ Int -- ^ Top margin (in pixels)
+ Int -- ^ Bottom margin (in pixels)
+
+ -- | Bottom of the screen with specific
+ -- left/right margins
+ | BottomP
+ Int -- ^ Left margin (in pixels)
+ Int -- ^ Bottom margin (in pixels)
+
+ -- | Bottom of the screen with specific width
+ -- (as screen percentage) and alignment
+ -- and alignment
+ | BottomW
+ Align -- ^ Alignement (L|C|R)
+ Int -- ^ Width as screen percentage (0-100)
+
+ -- | Bottom of the screen with specific width
+ -- (as screen percentage), height
+ -- and alignment
+ | BottomSize
+ Align -- ^ Alignement (L|C|R)
+ Int -- ^ Width as screen percentage (0-100)
+ Int -- ^ Height (in pixels)
+
+ -- | Static position and specific size
+ | Static { xpos :: Int -- ^ Position X (in pixels)
+ , ypos :: Int -- ^ Position Y (in pixels)
+ , width :: Int -- ^ Width (in pixels)
+ , height :: Int -- ^ Height (in pixels)
+ }
+
+ -- | Along with the position characteristics
+ -- specify the screen to display the bar
+ | OnScreen
+ Int -- ^ Screen id (primary is 0)
+ XPosition -- ^ Position
deriving ( Read, Show, Eq )
data Align = L | R | C deriving ( Read, Show, Eq )
@@ -110,3 +198,34 @@ instance Read SignalChan where
instance Show SignalChan where
show (SignalChan (Just _)) = "SignalChan (Just <tmvar>)"
show (SignalChan Nothing) = "SignalChan Nothing"
+
+data Widget = Icon String | Text String | Hspace Int32 deriving Show
+
+data BoxOffset = BoxOffset Align Int32 deriving (Eq, Show)
+
+-- margins: Top, Right, Bottom, Left
+data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (Eq, Show)
+
+data BoxBorder = BBTop
+ | BBBottom
+ | BBVBoth
+ | BBLeft
+ | BBRight
+ | BBHBoth
+ | BBFull
+ deriving (Read, Eq, Show)
+
+data Box = Box { bBorder :: BoxBorder
+ , bOffset :: BoxOffset
+ , bWidth :: CInt
+ , bColor :: String
+ , bMargins :: BoxMargins
+ } deriving (Eq, Show)
+
+data TextRenderInfo = TextRenderInfo { tColorsString :: String
+ , tBgTopOffset :: Int32
+ , tBgBottomOffset :: Int32
+ , tBoxes :: [Box]
+ } deriving Show
+
+type Segment = (Widget, TextRenderInfo, FontIndex, Maybe [Action])
diff --git a/src/Xmobar/Draw/Boxes.hs b/src/Xmobar/Draw/Boxes.hs
index 1358805..692e232 100644
--- a/src/Xmobar/Draw/Boxes.hs
+++ b/src/Xmobar/Draw/Boxes.hs
@@ -16,7 +16,6 @@
module Xmobar.Draw.Boxes (Line, boxLines, BoxRect, borderRect) where
import qualified Xmobar.Config.Types as T
-import qualified Xmobar.Run.Parsers as P
type Line = (Double, Double, Double, Double)
type BoxRect = (Double, Double, Double, Double)
@@ -25,19 +24,19 @@ type BoxRect = (Double, Double, Double, Double)
-- The Box is to be positioned between x0 and x1, with height ht, and drawn
-- with line width lw. The returned lists are coordinates of the beginning
-- and end of each line.
-boxLines :: P.Box -> Double -> Double -> Double -> [Line]
-boxLines (P.Box bd offset lw _ margins) ht x0 x1 =
+boxLines :: T.Box -> Double -> Double -> Double -> [Line]
+boxLines (T.Box bd offset lw _ margins) ht x0 x1 =
case bd of
- P.BBTop -> [rtop]
- P.BBBottom -> [rbot]
- P.BBVBoth -> [rtop, rbot]
- P.BBLeft -> [rleft]
- P.BBRight -> [rright]
- P.BBHBoth -> [rleft, rright]
- P.BBFull -> [rtop, rbot, rleft, rright]
+ T.BBTop -> [rtop]
+ T.BBBottom -> [rbot]
+ T.BBVBoth -> [rtop, rbot]
+ T.BBLeft -> [rleft]
+ T.BBRight -> [rright]
+ T.BBHBoth -> [rleft, rright]
+ T.BBFull -> [rtop, rbot, rleft, rright]
where
- (P.BoxMargins top right bot left) = margins
- (P.BoxOffset align m) = offset
+ (T.BoxMargins top right bot left) = margins
+ (T.BoxOffset align m) = offset
ma = fromIntegral m
(p0, p1) = case align of
T.L -> (0, -ma)
diff --git a/src/Xmobar/Draw/Cairo.hs b/src/Xmobar/Draw/Cairo.hs
index 7e22df4..dfcfd14 100644
--- a/src/Xmobar/Draw/Cairo.hs
+++ b/src/Xmobar/Draw/Cairo.hs
@@ -29,14 +29,13 @@ import Graphics.Rendering.Cairo.Types(Surface)
import qualified Xmobar.Config.Types as C
import qualified Xmobar.Config.Parse as ConfigParse
-import qualified Xmobar.Run.Parsers as P
import qualified Xmobar.Text.Pango as TextPango
import qualified Xmobar.Draw.Boxes as Boxes
import qualified Xmobar.Draw.Types as T
-type Renderinfo = (P.Segment, Surface -> Double -> Double -> IO (), Double)
-type BoundedBox = (Double, Double, [P.Box])
+type Renderinfo = (C.Segment, Surface -> Double -> Double -> IO (), Double)
+type BoundedBox = (Double, Double, [C.Box])
type Acc = (Double, T.Actions, [BoundedBox])
readColourName :: String -> (SRGB.Colour Double, Double)
@@ -63,10 +62,10 @@ renderLines color wd lns = do
mapM_ (\(x0, y0, x1, y1) ->
Cairo.moveTo x0 y0 >> Cairo.lineTo x1 y1 >> Cairo.stroke) lns
-segmentMarkup :: C.Config -> P.Segment -> String
-segmentMarkup conf (P.Text txt, info, idx, _actions) =
+segmentMarkup :: C.Config -> C.Segment -> String
+segmentMarkup conf (C.Text txt, info, idx, _actions) =
let fnt = TextPango.fixXft $ ConfigParse.indexedFont conf idx
- (fg, bg) = P.colorComponents conf (P.tColorsString info)
+ (fg, bg) = ConfigParse.colorComponents conf (C.tColorsString info)
attrs = [Pango.FontDescr fnt, Pango.FontForeground fg]
attrs' = if bg == C.bgColor conf
then attrs
@@ -74,8 +73,8 @@ segmentMarkup conf (P.Text txt, info, idx, _actions) =
in Pango.markSpan attrs' $ Pango.escapeMarkup txt
segmentMarkup _ _ = ""
-withRenderinfo :: Pango.PangoContext -> T.DrawContext -> P.Segment -> IO Renderinfo
-withRenderinfo ctx dctx seg@(P.Text _, inf, idx, a) = do
+withRenderinfo :: Pango.PangoContext -> T.DrawContext -> C.Segment -> IO Renderinfo
+withRenderinfo ctx dctx seg@(C.Text _, inf, idx, a) = do
let conf = T.dcConfig dctx
lyt <- Pango.layoutEmpty ctx
mk <- Pango.layoutSetMarkup lyt (segmentMarkup conf seg) :: IO String
@@ -88,25 +87,25 @@ withRenderinfo ctx dctx seg@(P.Text _, inf, idx, a) = do
Pango.layoutSetEllipsize lyt Pango.EllipsizeEnd
Pango.layoutSetWidth lyt (Just $ mx - off)
Cairo.renderWith s $ Cairo.moveTo off voff >> Pango.showLayout lyt
- return ((P.Text mk, inf, idx, a), slyt, wd)
+ return ((C.Text mk, inf, idx, a), slyt, wd)
-withRenderinfo _ _ seg@(P.Hspace w, _, _, _) =
+withRenderinfo _ _ seg@(C.Hspace w, _, _, _) =
return (seg, \_ _ _ -> return (), fromIntegral w)
-withRenderinfo _ dctx seg@(P.Icon p, _, _, _) = do
+withRenderinfo _ dctx seg@(C.Icon p, _, _, _) = do
let (wd, _) = T.dcIconLookup dctx p
ioff = C.iconOffset (T.dcConfig dctx)
vpos = T.dcHeight dctx / 2 + fromIntegral ioff
render _ off mx = when (off + wd <= mx) $ T.dcIconDrawer dctx off vpos p
return (seg, render, wd)
-drawBox :: T.DrawContext -> Surface -> Double -> Double -> P.Box -> IO ()
-drawBox dctx surf x0 x1 box@(P.Box _ _ w color _) =
+drawBox :: T.DrawContext -> Surface -> Double -> Double -> C.Box -> IO ()
+drawBox dctx surf x0 x1 box@(C.Box _ _ w color _) =
Cairo.renderWith surf $
renderLines color (fromIntegral w) (Boxes.boxLines box (T.dcHeight dctx) x0 x1)
drawSegmentBackground ::
- T.DrawContext -> Surface -> P.TextRenderInfo -> Double -> Double -> IO ()
+ T.DrawContext -> Surface -> C.TextRenderInfo -> Double -> Double -> IO ()
drawSegmentBackground dctx surf info x0 x1 =
when (bg /= C.bgColor conf && (top >= 0 || bot >= 0)) $
Cairo.renderWith surf $ do
@@ -114,19 +113,20 @@ drawSegmentBackground dctx surf info x0 x1 =
Cairo.rectangle x0 top (x1 - x0) (T.dcHeight dctx - bot - top)
Cairo.fillPreserve
where conf = T.dcConfig dctx
- (_, bg) = P.colorComponents conf (P.tColorsString info)
- top = fromIntegral $ P.tBgTopOffset info
- bot = fromIntegral $ P.tBgBottomOffset info
+ (_, bg) = ConfigParse.colorComponents conf (C.tColorsString info)
+ top = fromIntegral $ C.tBgTopOffset info
+ bot = fromIntegral $ C.tBgBottomOffset info
drawSegment :: T.DrawContext -> Surface -> Double -> Acc -> Renderinfo -> IO Acc
drawSegment dctx surface maxoff (off, acts, boxs) (segment, render, lwidth) = do
let end = min maxoff (off + lwidth)
(_, info, _, a) = segment
acts' = case a of Just as -> (as, off, end):acts; _ -> acts
- bs = P.tBoxes info
+ bs = C.tBoxes info
boxs' = if null bs then boxs else (off, end, bs):boxs
- drawSegmentBackground dctx surface info off end
- render surface off maxoff
+ when (end > off) $ do
+ drawSegmentBackground dctx surface info off end
+ render surface off maxoff
return (off + lwidth, acts', boxs')
renderOuterBorder :: C.Config -> Double -> Double -> Cairo.Render ()
@@ -172,6 +172,7 @@ drawSegments dctx surf = do
conf = T.dcConfig dctx
sWidth = foldl (\a (_,_,w) -> a + w) 0
ctx <- Pango.cairoCreateContext Nothing
+ Pango.cairoContextSetResolution ctx $ C.dpi conf
llyts <- mapM (withRenderinfo ctx dctx) left
rlyts <- mapM (withRenderinfo ctx dctx) right
clyts <- mapM (withRenderinfo ctx dctx) center
@@ -179,11 +180,10 @@ drawSegments dctx surf = do
drawCairoBackground dctx surf
#endif
(lend, as, bx) <- foldM (drawSegment dctx surf dw) (0, [], []) llyts
- let rw = sWidth rlyts
- rstart = max (lend + 1) (dw - rw - 1)
+ let [rw, cw] = map sWidth [rlyts, clyts]
+ rstart = dw - rw - 1
+ cstart = max (lend + 1) ((dw - cw) / 2.0)
cmax = rstart - 1
- cw = sWidth clyts
- cstart = lend + 1 + max 0 (dw - rw - lend - cw) / 2.0
(_, as', bx') <- foldM (drawSegment dctx surf cmax) (cstart, as, bx) clyts
(_, as'', bx'') <- foldM (drawSegment dctx surf dw) (rstart, as', bx') rlyts
drawBoxes dctx surf (reverse bx'')
diff --git a/src/Xmobar/Draw/Types.hs b/src/Xmobar/Draw/Types.hs
index 75dd714..9853c38 100644
--- a/src/Xmobar/Draw/Types.hs
+++ b/src/Xmobar/Draw/Types.hs
@@ -17,9 +17,8 @@
module Xmobar.Draw.Types where
-import Xmobar.Config.Types (Config)
+import Xmobar.Config.Types (Config, Segment)
import Xmobar.Run.Actions (Action)
-import Xmobar.Run.Parsers (Segment)
type Position = Double
type ActionPos = ([Action], Position, Position)
diff --git a/src/Xmobar/Plugins/Kraken.hs b/src/Xmobar/Plugins/Kraken.hs
index 2345b3d..5d565e0 100644
--- a/src/Xmobar/Plugins/Kraken.hs
+++ b/src/Xmobar/Plugins/Kraken.hs
@@ -36,7 +36,7 @@ instance Exec Kraken where
cb (display g)
loop mv g
- loop mvar (Map.fromList $ zip ps (repeat 0.0))
+ loop mvar (Map.fromList $ map (, 0.0) ps)
where
display :: Map.Map String Double -> String
diff --git a/src/Xmobar/Plugins/Monitors/Common/Output.hs b/src/Xmobar/Plugins/Monitors/Common/Output.hs
index bd60710..2d0e194 100644
--- a/src/Xmobar/Plugins/Monitors/Common/Output.hs
+++ b/src/Xmobar/Plugins/Monitors/Common/Output.hs
@@ -140,7 +140,7 @@ showWithUnits d n x
padString :: Int -> Int -> String -> Bool -> String -> String -> String
padString mnw mxw pad pr ellipsis s =
let len = length s
- rmin = if mnw < 0 then 0 else mnw
+ rmin = max mnw 0
rmax = if mxw <= 0 then max len rmin else mxw
(rmn, rmx) = if rmin <= rmax then (rmin, rmax) else (rmax, rmin)
rlen = min (max rmn len) rmx
diff --git a/src/Xmobar/Run/Parsers.hs b/src/Xmobar/Run/Parsers.hs
deleted file mode 100644
index 9b36786..0000000
--- a/src/Xmobar/Run/Parsers.hs
+++ /dev/null
@@ -1,244 +0,0 @@
-{-# LANGUAGE FlexibleContexts #-}
-
------------------------------------------------------------------------------
--- |
--- Module : Xmobar.Run.Parsers
--- Copyright : (c) Andrea Rossato
--- License : BSD-style (see LICENSE)
---
--- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
--- Stability : unstable
--- Portability : portable
---
--- Parsing for template substrings
---
------------------------------------------------------------------------------
-
-module Xmobar.Run.Parsers ( parseString
- , colorComponents
- , Segment
- , FontIndex
- , Box(..)
- , BoxBorder(..)
- , BoxOffset(..)
- , BoxMargins(..)
- , TextRenderInfo(..)
- , Widget(..)) where
-
-import Control.Monad (guard, mzero)
-import Data.Maybe (fromMaybe)
-import Data.Int (Int32)
-import Text.ParserCombinators.Parsec
-import Text.Read (readMaybe)
-import Foreign.C.Types (CInt)
-
-import Xmobar.Config.Types
-import Xmobar.Run.Actions
-
-data Widget = Icon String | Text String | Hspace Int32 deriving Show
-
-data BoxOffset = BoxOffset Align Int32 deriving (Eq, Show)
-
--- margins: Top, Right, Bottom, Left
-data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (Eq, Show)
-
-data BoxBorder = BBTop
- | BBBottom
- | BBVBoth
- | BBLeft
- | BBRight
- | BBHBoth
- | BBFull
- deriving (Read, Eq, Show)
-
-data Box = Box { bBorder :: BoxBorder
- , bOffset :: BoxOffset
- , bWidth :: CInt
- , bColor :: String
- , bMargins :: BoxMargins
- } deriving (Eq, Show)
-
-data TextRenderInfo = TextRenderInfo { tColorsString :: String
- , tBgTopOffset :: Int32
- , tBgBottomOffset :: Int32
- , tBoxes :: [Box]
- } deriving Show
-
-type Segment = (Widget, TextRenderInfo, FontIndex, Maybe [Action])
-
--- | Runs the string parser
-parseString :: Config -> String -> IO [Segment]
-parseString c s =
- case parse (stringParser ci 0 Nothing) "" s of
- Left _ -> return [(Text $ "Could not parse string: " ++ s
- , ci
- , 0
- , Nothing)]
- Right x -> return (concat x)
- where ci = TextRenderInfo (fgColor c) 0 0 []
-
--- | Splits a colors string into its two components
-colorComponents :: Config -> String -> (String, String)
-colorComponents conf c =
- case break (==',') c of
- (f,',':b) -> (f, b)
- (f, _) -> (f, bgColor conf)
-
-allParsers :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-allParsers c f a = textParser c f a
- <|> try (iconParser c f a)
- <|> try (hspaceParser c f a)
- <|> try (rawParser c f a)
- <|> try (actionParser c f a)
- <|> try (fontParser c a)
- <|> try (boxParser c f a)
- <|> colorParser c f a
-
--- | Gets the string and combines the needed parsers
-stringParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [[Segment]]
-stringParser c f a = manyTill (allParsers c f a) eof
-
--- | Parses a maximal string without markup.
-textParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-textParser c f a = do s <- many1 $
- noneOf "<" <|>
- try (notFollowedBy' (char '<')
- (try (string "fc=") <|>
- try (string "box") <|>
- try (string "fn=") <|>
- try (string "action=") <|>
- try (string "/action>") <|>
- try (string "icon=") <|>
- try (string "hspace=") <|>
- try (string "raw=") <|>
- try (string "/fn>") <|>
- try (string "/box>") <|>
- string "/fc>"))
- return [(Text s, c, f, a)]
-
--- | Parse a "raw" tag, which we use to prevent other tags from creeping in.
--- The format here is net-string-esque: a literal "<raw=" followed by a
--- string of digits (base 10) denoting the length of the raw string,
--- a literal ":" as digit-string-terminator, the raw string itself, and
--- then a literal "/>".
-rawParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-rawParser c f a = do
- string "<raw="
- lenstr <- many1 digit
- char ':'
- case reads lenstr of
- [(len,[])] -> do
- guard ((len :: Integer) <= fromIntegral (maxBound :: Int))
- s <- count (fromIntegral len) anyChar
- string "/>"
- return [(Text s, c, f, a)]
- _ -> mzero
-
--- | Wrapper for notFollowedBy that returns the result of the first parser.
--- Also works around the issue that, at least in Parsec 3.0.0, notFollowedBy
--- accepts only parsers with return type Char.
-notFollowedBy' :: Parser a -> Parser b -> Parser a
-notFollowedBy' p e = do x <- p
- notFollowedBy $ try (e >> return '*')
- return x
-
-iconParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-iconParser c f a = do
- string "<icon="
- i <- manyTill (noneOf ">") (try (string "/>"))
- return [(Icon i, c, f, a)]
-
-hspaceParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-hspaceParser c f a = do
- string "<hspace="
- pVal <- manyTill digit (try (string "/>"))
- return [(Hspace (fromMaybe 0 $ readMaybe pVal), c, f, a)]
-
-actionParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-actionParser c f act = do
- string "<action="
- command <- choice [between (char '`') (char '`') (many1 (noneOf "`")),
- many1 (noneOf ">")]
- buttons <- (char '>' >> return "1") <|> (space >> spaces >>
- between (string "button=") (string ">") (many1 (oneOf "12345")))
- let a = Spawn (toButtons buttons) command
- a' = case act of
- Nothing -> Just [a]
- Just act' -> Just $ a : act'
- s <- manyTill (allParsers c f a') (try $ string "</action>")
- return (concat s)
-
-toButtons :: String -> [Button]
-toButtons = map (\x -> read [x])
-
--- | Parsers a string wrapped in a color specification.
-colorParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-colorParser (TextRenderInfo _ _ _ bs) fidx a = do
- c <- between (string "<fc=") (string ">") colors
- let colorParts = break (==':') c
- let (ot,ob) = case break (==',') (Prelude.drop 1 $ snd colorParts) of
- (top,',':btm) -> (top, btm)
- (top, _) -> (top, top)
- tri = TextRenderInfo (fst colorParts)
- (fromMaybe (-1) $ readMaybe ot)
- (fromMaybe (-1) $ readMaybe ob)
- bs
- s <- manyTill (allParsers tri fidx a) (try $ string "</fc>")
- return (concat s)
-
--- | Parses a string wrapped in a box specification.
-boxParser :: TextRenderInfo -> FontIndex -> Maybe [Action] -> Parser [Segment]
-boxParser (TextRenderInfo cs ot ob bs) f a = do
- c <- between (string "<box") (string ">")
- (option "" (many1 (alphaNum
- <|> char '='
- <|> char ' '
- <|> char '#'
- <|> char ',')))
- let b = Box BBFull (BoxOffset C 0) 1 cs (BoxMargins 0 0 0 0)
- let g = boxReader b (words c)
- s <- manyTill
- (allParsers (TextRenderInfo cs ot ob (g : bs)) f a)
- (try $ string "</box>")
- return (concat s)
-
-boxReader :: Box -> [String] -> Box
-boxReader b [] = b
-boxReader b (x:xs) = do
- let (param,val) = case break (=='=') x of
- (p,'=':v) -> (p, v)
- (p, _) -> (p, "")
- boxReader (boxParamReader b param val) xs
-
-boxParamReader :: Box -> String -> String -> Box
-boxParamReader b _ "" = b
-boxParamReader (Box bb off lw fc mgs) "type" val =
- Box (fromMaybe bb $ readMaybe ("BB" ++ val)) off lw fc mgs
-boxParamReader (Box bb (BoxOffset alg off) lw fc mgs) "offset" (a:o) =
- Box bb (BoxOffset align offset) lw fc mgs
- where offset = fromMaybe off $ readMaybe o
- align = fromMaybe alg $ readMaybe [a]
-boxParamReader (Box bb off lw fc mgs) "width" val =
- Box bb off (fromMaybe lw $ readMaybe val) fc mgs
-boxParamReader (Box bb off lw _ mgs) "color" val =
- Box bb off lw val mgs
-boxParamReader (Box bb off lw fc mgs@(BoxMargins mt mr mb ml)) ('m':pos) val = do
- let mgs' = case pos of
- "t" -> BoxMargins (fromMaybe mt $ readMaybe val) mr mb ml
- "r" -> BoxMargins mt (fromMaybe mr $ readMaybe val) mb ml
- "b" -> BoxMargins mt mr (fromMaybe mb $ readMaybe val) ml
- "l" -> BoxMargins mt mr mb (fromMaybe ml $ readMaybe val)
- _ -> mgs
- Box bb off lw fc mgs'
-boxParamReader b _ _ = b
-
--- | Parsers a string wrapped in a font specification.
-fontParser :: TextRenderInfo -> Maybe [Action] -> Parser [Segment]
-fontParser c a = do
- f <- between (string "<fn=") (string ">") colors
- s <- manyTill (allParsers c (fromMaybe 0 $ readMaybe f) a) (try $ string "</fn>")
- return (concat s)
-
--- | Parses a color specification (hex or named)
-colors :: Parser String
-colors = many1 (alphaNum <|> char ',' <|> char ':' <|> char '#')
diff --git a/src/Xmobar/System/Environment.hs b/src/Xmobar/System/Environment.hs
index 25802fe..42483ca 100644
--- a/src/Xmobar/System/Environment.hs
+++ b/src/Xmobar/System/Environment.hs
@@ -13,14 +13,14 @@
-----------------------------------------------------------------------------
module Xmobar.System.Environment(expandEnv) where
-import Data.Maybe (fromMaybe)
-import System.Environment (lookupEnv)
+import qualified Data.Maybe as M
+import qualified System.Environment as E
expandEnv :: String -> IO String
expandEnv "" = return ""
expandEnv (c:s) = case c of
'$' -> do
- envVar <- fromMaybe "" <$> lookupEnv e
+ envVar <- M.fromMaybe "" <$> E.lookupEnv e
remainder <- expandEnv s'
return $ envVar ++ remainder
where (e, s') = getVar s
diff --git a/src/Xmobar/Text/Loop.hs b/src/Xmobar/Text/Loop.hs
index 05379cd..5d2c43f 100644
--- a/src/Xmobar/Text/Loop.hs
+++ b/src/Xmobar/Text/Loop.hs
@@ -45,4 +45,4 @@ eventLoop cfg signal tv = do
updateString :: Config -> TVar [String] -> IO String
updateString conf v = do
s <- readTVarIO v
- format conf (concat s)
+ return $ format conf (concat s)
diff --git a/src/Xmobar/Text/Output.hs b/src/Xmobar/Text/Output.hs
index 783a5bb..677b6d2 100644
--- a/src/Xmobar/Text/Output.hs
+++ b/src/Xmobar/Text/Output.hs
@@ -15,13 +15,15 @@
module Xmobar.Text.Output (initLoop, format) where
-import Xmobar.Config.Types (Config(textOutputFormat, additionalFonts, font)
- , TextOutputFormat(..))
-import Xmobar.Run.Parsers ( Segment
- , Widget(..)
- , parseString
- , tColorsString
- , colorComponents)
+import Xmobar.Config.Types ( Config (..)
+ , TextOutputFormat (..)
+ , Segment
+ , Widget (..)
+ , tColorsString)
+
+
+import Xmobar.Config.Parse (colorComponents)
+import Xmobar.Config.Template (parseString)
import Xmobar.Text.Ansi (withAnsiColor)
import Xmobar.Text.Pango (withPangoMarkup)
@@ -47,9 +49,9 @@ formatWithColor conf (Hspace n, i, x, y) =
formatWithColor conf (Text $ replicate (fromIntegral n) ' ', i, x, y)
formatWithColor _ _ = ""
-format :: Config -> String -> IO String
+format :: Config -> String -> String
format conf s = do
- segments <- parseString conf s
+ let segments = parseString conf s
case textOutputFormat conf of
- Swaybar -> return $ formatSwaybar conf segments
- _ -> return (concatMap (formatWithColor conf) segments)
+ Swaybar -> formatSwaybar conf segments
+ _ -> concatMap (formatWithColor conf) segments
diff --git a/src/Xmobar/Text/Swaybar.hs b/src/Xmobar/Text/Swaybar.hs
index a2fc585..355de06 100644
--- a/src/Xmobar/Text/Swaybar.hs
+++ b/src/Xmobar/Text/Swaybar.hs
@@ -24,16 +24,16 @@ import Data.ByteString.Lazy.UTF8 (toString)
import GHC.Generics
-import Xmobar.Config.Types (Config (additionalFonts))
-
-import Xmobar.Run.Parsers ( Segment
- , Widget(..)
- , Box(..)
- , BoxBorder(..)
- , FontIndex
- , tBoxes
- , tColorsString
- , colorComponents)
+import Xmobar.Config.Types ( Config (additionalFonts)
+ , Segment
+ , Widget(..)
+ , Box(..)
+ , BoxBorder(..)
+ , FontIndex
+ , tBoxes
+ , tColorsString)
+
+import Xmobar.Config.Parse (colorComponents)
import Xmobar.Text.SwaybarClicks (startHandler)
import Xmobar.Text.Pango (withPangoFont)
diff --git a/src/Xmobar/X11/Draw.hs b/src/Xmobar/X11/Draw.hs
index a056136..c0a8964 100644
--- a/src/Xmobar/X11/Draw.hs
+++ b/src/Xmobar/X11/Draw.hs
@@ -25,7 +25,6 @@ import Foreign.C.Types as FT
import qualified Graphics.X11.Xlib as X11
import qualified Xmobar.Config.Types as C
-import qualified Xmobar.Run.Parsers as P
import qualified Xmobar.Draw.Types as D
import qualified Xmobar.Draw.Cairo as DC
@@ -69,7 +68,7 @@ withPixmap disp win (X11.Rectangle _ _ w h) depth action = do
X11.sync disp True
return res
-draw :: [[P.Segment]] -> T.X [D.ActionPos]
+draw :: [[C.Segment]] -> T.X [D.ActionPos]
draw segments = do
xconf <- ask
let disp = T.display xconf
@@ -89,7 +88,7 @@ draw segments = do
#ifdef XRENDER
color = C.bgColor conf
alph = C.alpha conf
- XRender.drawBackground disp p color alph (X11.Rectangle 0 0 w h)
+ XRender.drawBackground disp p color alph rect
#endif
CS.withXlibSurface disp p vis (fromIntegral w) (fromIntegral h) render
diff --git a/src/Xmobar/X11/Events.hs b/src/Xmobar/X11/Events.hs
index 4334f6b..fbd2bd0 100644
--- a/src/Xmobar/X11/Events.hs
+++ b/src/Xmobar/X11/Events.hs
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- |
-- Module: Xmobar.X11.Events
--- Copyright: (c) 2018 Jose Antonio Ortega Ruiz
+-- Copyright: (c) 2018, 2022 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
@@ -17,20 +17,19 @@
module Xmobar.X11.Events(nextEvent') where
-import Control.Concurrent
-import System.Posix.Types (Fd(..))
+import qualified Control.Concurrent as C
+import qualified System.Posix.Types as T
-import Graphics.X11.Xlib (
- Display(..), XEventPtr, nextEvent, pending, connectionNumber)
+import qualified Graphics.X11.Xlib as X
-- | A version of nextEvent that does not block in foreign calls.
-nextEvent' :: Display -> XEventPtr -> IO ()
+nextEvent' :: X.Display -> X.XEventPtr -> IO ()
nextEvent' d p = do
- pend <- pending d
+ pend <- X.pending d
if pend /= 0
- then nextEvent d p
+ then X.nextEvent d p
else do
- threadWaitRead (Fd fd)
+ C.threadWaitRead (T.Fd fd)
nextEvent' d p
where
- fd = connectionNumber d
+ fd = X.connectionNumber d
diff --git a/src/Xmobar/X11/Loop.hs b/src/Xmobar/X11/Loop.hs
index 599e680..da16402 100644
--- a/src/Xmobar/X11/Loop.hs
+++ b/src/Xmobar/X11/Loop.hs
@@ -35,10 +35,10 @@ import qualified Graphics.X11.Xinerama as Xinerama
import qualified Graphics.X11.Xrandr as Xrandr
import qualified Xmobar.Config.Types as C
+import qualified Xmobar.Config.Template as CT
import qualified Xmobar.Run.Actions as A
import qualified Xmobar.Run.Loop as L
-import qualified Xmobar.Run.Parsers as P
import qualified Xmobar.System.Utils as U
import qualified Xmobar.System.Signal as S
@@ -145,15 +145,15 @@ signalLoop xc@(T.XConf d r w fs is cfg) actions signalv strs = do
r' <- W.repositionWin d w (NE.head fs) rcfg
signalLoop (T.XConf d r' w fs is rcfg) actions signalv strs
-parseSegments :: C.Config -> STM.TVar [String] -> IO [[P.Segment]]
+parseSegments :: C.Config -> STM.TVar [String] -> IO [[C.Segment]]
parseSegments conf v = do
s <- STM.readTVarIO v
let l:c:r:_ = s ++ repeat ""
- MR.liftIO $ mapM (P.parseString conf) [l, c, r]
+ return $ map (CT.parseString conf) [l, c, r]
-updateIconCache :: T.XConf -> [[P.Segment]] -> IO T.XConf
+updateIconCache :: T.XConf -> [[C.Segment]] -> IO T.XConf
updateIconCache xc@(T.XConf d _ w _ c cfg) segs = do
- let paths = [p | (P.Icon p, _, _, _) <- concat segs]
+ let paths = [p | (C.Icon p, _, _, _) <- concat segs]
c' <- Bitmap.updateCache d w c (C.iconRoot cfg) paths
return $ xc {T.iconCache = c'}
diff --git a/src/Xmobar/X11/Window.hs b/src/Xmobar/X11/Window.hs
index ad7ebf7..87d56f4 100644
--- a/src/Xmobar/X11/Window.hs
+++ b/src/Xmobar/X11/Window.hs
@@ -86,10 +86,14 @@ setPosition c p rs ht =
T.Top -> X.Rectangle rx ry rw h
T.TopP l r -> X.Rectangle (rx + fi l) ry (rw - fi l - fi r) h
T.TopH ch -> X.Rectangle rx ry rw (mh ch)
+ T.TopHM ch l r t _ ->
+ X.Rectangle (rx + fi l) (ry + fi t) (rw - fi l - fi r) (mh ch)
T.TopW a i -> X.Rectangle (ax a i) ry (nw i) h
T.TopSize a i ch -> X.Rectangle (ax a i) ry (nw i) (mh ch)
T.Bottom -> X.Rectangle rx ny rw h
T.BottomH ch -> X.Rectangle rx (ny' ch) rw (mh ch)
+ T.BottomHM ch l r _ b ->
+ X.Rectangle (rx + fi l) (ry + fi rh - fi b - fi (mh ch)) (rw - fi l - fi r) (mh ch)
T.BottomW a i -> X.Rectangle (ax a i) ny (nw i) h
T.BottomP l r -> X.Rectangle (rx + fi l) ny (rw - fi l - fi r) h
T.BottomSize a i ch -> X.Rectangle (ax a i) (ny' ch) (nw i) (mh ch)
@@ -160,18 +164,20 @@ getRootWindowHeight srs = maximum (map getMaxScreenYCoord srs)
getStrutValues :: X.Rectangle -> T.XPosition -> Int -> [Int]
getStrutValues r@(X.Rectangle x y w h) p rwh =
case p of
- T.OnScreen _ p' -> getStrutValues r p' rwh
- T.Top -> [0, 0, st, 0, 0, 0, 0, 0, nx, nw, 0, 0]
- T.TopH _ -> [0, 0, st, 0, 0, 0, 0, 0, nx, nw, 0, 0]
- T.TopP _ _ -> [0, 0, st, 0, 0, 0, 0, 0, nx, nw, 0, 0]
- T.TopW _ _ -> [0, 0, st, 0, 0, 0, 0, 0, nx, nw, 0, 0]
- T.TopSize {} -> [0, 0, st, 0, 0, 0, 0, 0, nx, nw, 0, 0]
- T.Bottom -> [0, 0, 0, sb, 0, 0, 0, 0, 0, 0, nx, nw]
- T.BottomH _ -> [0, 0, 0, sb, 0, 0, 0, 0, 0, 0, nx, nw]
- T.BottomP _ _ -> [0, 0, 0, sb, 0, 0, 0, 0, 0, 0, nx, nw]
- T.BottomW _ _ -> [0, 0, 0, sb, 0, 0, 0, 0, 0, 0, nx, nw]
- T.BottomSize {} -> [0, 0, 0, sb, 0, 0, 0, 0, 0, 0, nx, nw]
- T.Static {} -> getStaticStrutValues p rwh
+ T.OnScreen _ p' -> getStrutValues r p' rwh
+ T.Top -> [0, 0, st , 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.TopH _ -> [0, 0, st , 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.TopHM _ _ _ _ b -> [0, 0, st+b, 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.TopP _ _ -> [0, 0, st , 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.TopW _ _ -> [0, 0, st , 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.TopSize {} -> [0, 0, st , 0 , 0, 0, 0, 0, nx, nw, 0 , 0 ]
+ T.Bottom -> [0, 0, 0 , sb , 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.BottomH _ -> [0, 0, 0 , sb , 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.BottomHM _ _ _ t _ -> [0, 0, 0 , sb+t, 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.BottomP _ _ -> [0, 0, 0 , sb , 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.BottomW _ _ -> [0, 0, 0 , sb , 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.BottomSize {} -> [0, 0, 0 , sb , 0, 0, 0, 0, 0 , 0 , nx, nw]
+ T.Static {} -> getStaticStrutValues p rwh
where st = fi y + fi h
sb = rwh - fi y
nx = fi x
diff --git a/xmobar.cabal b/xmobar.cabal
index 8b331f5..4d17849 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -109,13 +109,13 @@ library
other-modules: Paths_xmobar,
Xmobar.Config.Types,
Xmobar.Config.Parse,
+ Xmobar.Config.Template,
Xmobar.Run.Types,
Xmobar.Run.Timer,
Xmobar.Run.Template,
Xmobar.Run.Exec,
Xmobar.Run.Runnable
Xmobar.Run.Actions,
- Xmobar.Run.Parsers,
Xmobar.Run.Loop,
Xmobar.Draw.Boxes,
Xmobar.Draw.Cairo,