Cursors in GTK+

History

Cursors have traditionally been a big mess in Linux.

The X11 cursor font has been passed down to us from times immemorial, and given us gems such as gumby () or trek (). Unfortunately for us, this state of affairs was frozen into the GDK api with the GdkCursorType enumeration and the gdk_cursor_new() function.

Later on, the Xcursor library came around. It invented its own image format for storing cursors and brought us cursor themes, but didn’t do anything to answer the question “What cursors should my cursor theme provide ?”

Since there is no official list of recommended cursor names, cursor themes frequently provide all the variants of cursor names that have been spotted in the wild. As an example, here is the list of cursors included in the oxygen cursor theme. If you are wondering, the hex strings in this list are a clever trick of Xcursor to retrofit themed cursors underneath core X11 applications that use cursors from the cursor font mentioned above.

CSS to the rescue

About a year ago, we decided to finally improve the GTK+ cursor story. Thankfully, the CSS3 spec contains a decent list of cursor names that can be reasonably expected to be available across platforms.

Standard cursorsSince the GdkCursorType enumeration contains too much nonsense and is not easily extensible, we decided to make gdk_cursor_new_from_name() the recommended API for obtaining cursors. The documentation for this function now lists the CSS cursor names (follow the link above to see it), and the cursor handling code in the various GDK backends tries hard to give you meaningful cursors for all of these names.

On some platforms (such as X11 with a random cursor theme), we may have to fall back to the default arrow cursor if a certain cursor is not present in the theme. As part of this general overhaul of the cursor code, the Windows backend grew support for cursor themes.

GTK+ itself is now using gdk_cursor_new_from_name() exclusively, with the standard cursor names. And gtk3-demo includes a demo that shows all the standard cursors and lets you try them out. The screenshot above shows it.

The changes described here went into GTK+ 3.18, which was released about 9 months ago.

What you should do in your application

Most likely, you don’t have to do anything! GTK+ widgets use suitable cursors all by themselves, and you can benefit from that without any extra work.

If your application is creating its own cursors for whatever reason, you should check carefully if one of the standard cursors shown above is suitable for you. Using a standard cursor ensures that you will get a suitable cursor regardless of the platform your application is running on and regardless of the cursor theme the user has chosen.

Please use gdk_cursor_new_from_name() to generate your themed cursor, since this is now the preferred API for this task.

This Week in GTK+ – 1

What’s up with GTK+ for the week of 9 May 2016 – 15 May 2016

In this last week, GTK+ has seen 51 commits, with 5375 lines added and 4970 lines removed.

Planning and Status

The 3.22 development cycle is picking up pace while we go through the items of the Roadmap.

Notable changes
  • Olivier Fourdan fixed scroll event handling in GtkMenu, to ensure that it behaves consistently on X11 and Wayland with regards to smooth and discrete scrolling
  • The list of available protocols in the Connect to Server help popover is now populated using the list of supported schemes in GVFS, thanks to Georges Basile Stavracas Neto
  • Benjamin Otte has pushed a commit that lets GtkWidget emit the style-updated signal on unrealized widgets instead of delaying until realization; the original behavior was the result of an older optimization to avoid too many invalidations during construction, but the style system has improved over the years.
  • Timm Bäder pushed various clean up commits over various widgets, like GtkListBox, GtkStack, and GtkToolbar.
Bugs fixed
  • Bug 766166 key bindings in gtk.css are ignored
  • Bug 766207 Fix build on pre-C99 compilers
  • Bug 765939 [Wayland] very slow scrolling in GtkMenu using the touchpad
  • Bug 756570 gtkplacesview no longer provides guidance on address formats
  • Bug 766120 Scale draw_value() align changed from centre/right (H/V) to left, causing significant visual regression
  • Bug 766233 Crash when server does not support XI2
  • Bug 766175 Translation of quotes may misinterpreted by GTK sidebar
  • Bug 765700 GtkPaned use causes “How does the code know the size to allocate?”
  • Bug 682080 Gtk:ERROR:gtktoolbar.c:2271:logical_to_physical: assertion failed: (logical == 0)
  • Bug 766458 widget: fix GtkLabelAccessible NULL links.
Get Involved

Interested in working on GTK+? Look at the list of bugs for newcomers and join the IRC channel #gtk+ on irc.gnome.org.

This Week in GTK – 0

In order to improve the communication between the GTK team and the rest of the GNOME platform, as well as application developers, we’re going to start writing weekly status reports on what happens in GTK and the rest of the core GNOME platform.

These reports are heavily inspired by the ones that the Servo team writes.

You can expect a weekly post on this blog every Monday; we’ll look at notable changes; new contributors; new features or deprecations; and scheduled events.

If you have questions, as usual, direct them to the GTK development mailing list.

Have fun!

Hello, World! (Reprise)

Hi all, and welcome back to the GTK+ development blog.

We’ve neglected this blog for a while, after the 3.0 release, but we think it’s kind of important to have a place where to talk about GTK+ (and the rest of the core GNOME platform), how it’s changing, and where it’s going.

Going forward, we are not going to use this blog for announcements — though if you want the, you can simply subscribe to the gnome-announcement mailing list. Instead, we are going to use this space to present what is happening in GTK+; to discuss the road map; to spotlight some new feature, and maybe some old one that is not well known.

Stay tuned, and as usual: have fun!

Newly designed gtk.org now up and running!

Originally, the website for http://www.gtk.org was going to be updated in line with the release for GTK+ 3.0 but there were a few set backs and more review needed. Finally, it’s up and running thanks to a lot of help from Devin Samarin and comments from the GTK+ community.

We have more plans to improve things on the website such as business support around GTK+ which is not really obvious enough on the current website. As part of the updates to the new website, we now list more recently established maintainers of the toolkit (seen on the Development page).

GTK+ 3.0 Released

GTK+ 3.0 is a major new version of GTK+, containing far too many changes to list them all here.

The major highlights include:

  • Cairo drawing throughout. GDK no longer wraps the antiquated X11 drawing API; we’ve made a clean break and exclusively rely on cairo for all our drawing needs now. This has also enabled us to remove several other X11-centric concepts such as GCs, colormaps and pixmaps.
  • Modern input device handling. The input device handling in GDK has long been a sadly neglected area. This has changed; with 3.0, GTK+ steps into the modern world of XI2 with full support for multiple pointers, keyboards and other gizmos.
  • A new theming API which sports a familiar CSS syntax for theme configuration and other improvements such as animated state transitions.
  • More flexible geometry management, with support for height-for-width, for both widgets and cell renderers.
  • Multiple backend support for GDK. With GTK+ 2.x, you had to recompile your application to have it work with a different GDK backend. In GTK+ 3, multiple GDK backends can be built into a single library and selected at runtime.
  • Easy application support. With the integration of D-Bus support in GIO, we could finally add a GtkApplication class that handles a lot of the platform integration aspects of writing an application, such as keeping track of open Windows, ensuring uniqueness, exporting actions, etc.
  • Of course, there’s some new widgets as well, such as a switch and an application chooser.

GTK+ is the work of hundreds of contributors, far too many to list them all here. But I want to take the time to thank some people who contributed in a major way:

  • Carlos Garnacho (Lanedo), for his work on XI2 support and the new theme system
  • Benjamin Otte (Red Hat), for his work on GDK and cairo drawing
  • Tristan Van Berkom (Openismus), for his work on geometry management
  • Colin Walters (Red Hat), for his work on GtkApplication
  • Ryan Lortie (Codethink), for his work on dconf, GSettings and GtkApplication
  • Javier Jardón, for tireless code, build and documentation cleanup

GTK+ 2.20 Released

GTK+ 2.20 adds new functionality while maintaining source and binary compatibility with GTK+ 2.18. Highlights of new features and improvements in GTK+ 2.20 are:

Noteworthy changes:

  • GtkSpinner, GtkCellRendererSpinner – A new widget that renders a ‘spinner’ animation to indicate ongoing activity. The corresponding cell renderer renders the same animation inside a treeview
  • GtkOffscreenWindow – A new toplevel container widget to manage offscreen rendering of child widgets
  • GtkNotebook – You can now show ‘action widgets’ in the space that is not occupied by tabs. This functionality is also available in GtkBuilder via the ‘action-start’ and ‘action-end’ child types.
  • Filechooser – GtkFileSystemModel has been reimplemented, for major speedup and simplifications.
  • Keyboard handling – The compose sequences understood by the builtin input method have been synced with X.org, and the additional sequences have been rationalized
  • Mnemonic underlines – Can now optionally be hidden until the Alt key is pressed, this can be turned on with the gtk-auto-mnemonics setting
  • Keyboard accelerators – The Super, Meta and Hyper modifiers are working more reliably
  • GDK – There is a new function to get the ‘primary’ monitor in multi-monitor setups: gdk_screen_get_primary_monitory.
  • gdk-pixbuf – Embedded color profiles in png and tiff images can be stored and retrieved. Support for the QTIF image format has been added
  • Win32 – XP themes have been disabled since they don’t work
  • OS X – GTK+ uses standard Mac keyboard shortcuts (Cmd-X/Cmd-C instead of Ctrl-X/Ctrl-C, etc). The handling of multi-monitor setups has been greatly improved
  • Introspection support – Introspection data is now included in GTK+ itself. As a consequence, a dependency on gobject-introspection has been added

GLib 2.24.0 released

GLib 2.22 is a stable release adding an incremental improvement in functionality over GLib 2.20 while maintaining binary and source compatibility. Major changes include:

  • The requirements for g_thread_init() have been relaxed slightly, it can be called multiple times, and does not have to be the first call. GObject now links to GThread and threads are enabled automatically when g_type_init() is called. Thread-safety issuesvwith boxed types in GObject have been fixed. The -pthread flag has been added to all gmodule .pc files, because it is not generally permissible to load modules that are linked against libpthread if the program has not been compiled with threading support.
  • GType now has a G_DEFINE_INTERFACE convenience macro
  • GIO supports lazy loading of GIO modules, and there is a new gio-querymodule utility that goes along with this. Packagers will need to adapt to this.
  • GIO uses splice(2) to transfer data between file descriptors without extraneous copies.
  • The GVariant variant datatype has been added.

GTK+ 2.18 stable release

GTK+ 2.18 adds new functionality while maintaining source and binary compatibility with GTK+ 2.16. Highlights of new features and improvements in GTK+ 2.18 are:

GtkInfoBar
A new widget to show a transient ‘message area’ inside a content pane. The API is similar to GtkDialog and supports theming for different message types (warnings, errors, etc)

GtkBuilder

  • Scale marks can be specified in builder markup
  • GtkAssistant action widgets can be added in builder markup

GtkLabel
GtkLabel can show embedded URLs, much like SexyUrlLabe

GtkEntry
GtkEntry has been refactored to follow the model-view pattern, with GtkEntryBuffer as model. One intended use case for this is to support ‘secure memory’ for password entries

File chooser

  • Backup files are hidden by default
  • GTK+ remembers the sorting state of the file list
  • File sizes are shown by default
  • The ‘Create Folder’ button can be disabled with the the ::create-folders property

Printing support

  • GTK+ supports authentication against CUPS servers
  • A backend for the PAPI printing system has been added
  • The file and lpr backends can print multiple pages per sheet
  • The file backend can produce svg files
  • GTK+ supports printing an application-defined ‘selection’ in addition to the usual page ranges
  • The print dialog can optinally include the page setup controls, avoiding the need for a separate page setup dialog in many situations

Theming support

  • The bullet character used in invisible entries can be set by themes with the ::invisible-char style property
  • The file chooser can show different icons for xdg user dirs. The icon names are folder-documents, folder-download, folder-music, folder-pictures, folder-publicshare, folder-templates and folder-video
  • The GtkInfoBar uses symbolic colors for theming its background color depending on the message type. The color names are info_fg_color, info_bg_color, warning_fg_color”, warning_bg_color, etc.

GDK changes
GDK has been rewritten to use ‘client-side windows’. This means that GDK maintains its own window hierarchy and only uses X windows where it is necessary or explicitly requested. Some of the benefits of this change are

  • Reduced flicker
  • The ability to do transformed and animated rendering of widgets
  • Easier embedding of GTK+ widgets, e.g. into Clutter scene graphs
  • See gdk-demo for some simple examples of client-side windows in action. See the documentation for information about possible problems when moving to client-side windows.

For more details and lists of fixed bugs, see the
announcements for the 2.17.x development releases: 2.17.0, 2.17.1, 2.17.2, 2.17.3, 2.17.4, 2.17.5, 2.17.6, 2.17.8, 2.17.9, 2.17.10, 2.17.11

GLib 2.22 Stable Release

GLib 2.22 is a stable release adding an incremental improvement in functionality over GLib 2.20 while maintaining binary and source compatibility.

Major new features include:

  • GArray, GPtrArray, GByteArray, GTree and GMappedFile can be reference counted.
  • GLib can be forced to reload the XDG user directory mapping.
  • The GLib mainloop supports per-thread default contexts.
  • GIO now provides types and methods for IP addresses and UNIX domain socket addresses.
  • GResolver provides asynchronous and cancellable APIs for resolving hostnames, reverse lookup of IP addresses and resolving SRV records.
  • Support for network IO has been added to GIO, including low-level socket API and high-level API for network connections and services.
  • GIOStream and its subclasses have gained support for read-write access.
  • GIO supports starting and stopping of drives, which can be used in connection with external hard disk enclosures, disk arrays, iSCSI devices, etc.
  • GIO supports user interaction during unmount and eject operations.
  • GIO can store and retrieve per-file metadata.

For more details and lists of fixed bugs, see the announcements of the 2.21.x development releases: 2.21.0, 2.21.1, 2.21.2, 2.21.3, 2.21.4, 2.21.5 and 2.21.6