简体   繁体   中英

Window Manager Themes and X11

In some WMs it is possible to choose theme which affects how windows are displayed, eg how a background of a button is coloured.

If I draw a window using bare Xlib calls, what should I do to conform to these theme-affected settings? Ie am I supposed to write specific code for every possible WM? How is it resolved in general?

There are several theme types and they sometimes play together, but they should not be confused.

  • Window manager/border themes describe the decorations of each window, not the content
  • UI toolkit themes/widget themes describe how buttons, text fields etc. are drawn within a window
  • Icon themes describe which icons are used, covering application icons as well as file icons, action icons, toolbar icons etc.
  • Color themes define a palette of colors to be used within the framework of the other themes
  • Pointer themes define a set of mouse pointer icons

Some desktop environments bundle all these themes in "desktop" themes, or at least provide a frontend to choose all of them. Yet, these themes are independent from the desktop environment and also from each other. It is possible to set them using configuration files.

If you want your application to fit with the user's preferences, first of all you should adhere to the Icon theme. The Pointer theme is taken care of by the X server, as long as you only use stock mouse icons and don't upload your own to the X server.

The second obvious thing would be the Color theme, but unfortunately there is no standard for color themes, both Gtk+ and Qt frameworks provide this functionality in an independent fashion (and desktop theme configurators understand and manipulate both to provide consistency). You could do some magic to find out whether the user prefers Gtk+ colors or Qt colors (eg, is running Gnome or KDE) and then extract the colors somewhat from there.

The hardest thing however is to provide a look and feel of your UI elements that is true to the UI toolkit theme(s) the user has chosen. First you would again have to decide between Gtk+ and Qt (other toolkits that are themeable exist as well, but are typically not themed by the user, or niche players like Enlightenment). Then you would have to re-implement the same functionality. Interestingly, many themes come with their own theme engine in Gtk+, and it is possible to let the theme engine do the work for you. An approach that was picked-up by several parties already. Examples:

  • Java Swing supports mimicing Gtk+ applications by implementing the Gtk+ themeing API and letting the Gtk+ theme engines do the work, works with some inconsistencies.
  • Firefox and other Mozilla Apps using XUL also do this, but there are always annoying differences, starting with the default font size.
  • Qt itself has a compatibility Gtk+ theme, that basically does the same; this one works pretty well.

My suggestion is to not reinvent the wheel, instead use Qt (or Gtk+ if you prefer) for GUI elements that go beyond basic drawing operations. Note that from my experience, even primitive drawing is typically better done with Qt than with Xlib. The user gets the look&feel she expects ( not only the look), the interface is rich and stable, and you save considerable time writing all this stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM