Multiple screens in the lighthouse


Sometimes one isn't enough

 The Twin Lighthouses of Thacher Island - Carol Sampson

When one isn't enough

Here's a quick note on a pretty cool and easy to implement feature: multiple screens. From the lighthouse perspective, there are two new functions of interest:

  • virtual void QPlatformIntegration::moveToScreen(QWidget *widget, int screen) - This function is a request by Qt for the plugin to move a widget to a screen. The widget should already have a window and window surface associated with it. The screen number is an index into the list of screens the plugin provides via QPlatformIntegration::screens(). The default implementation ignores the request.
  • virtual bool QPlatformIntegration::isVirtualDesktop() - This reports whether the set of screens present one virtual screen, or a set of discrete screens. The default implementation returns false. If you're unfamiliar with the distinction, we'll spend a moment on the virtual desktop concept further down.

Defining the landscape

With a single screen, geometry is easy. Start with (0,0) in the upper left corner, and extend into positive territory down and to the right. Each coordinate pair uniquely defines a point in two-dimensional space.

To keep things simple for application writers (and us too!), we decided to maintain this model. To illustrate, let's imagine three screens that measure 320x240 each. If we place the first two screens side by side, the first screen covers from (0,0) to (319,239). The second screen begins at (320,0) and ends at (639, 239). The third screen is placed below the first, covering from (0, 240) to (319, 479).

lighthouse screen geometry

 Multiscreen geometry

Virtual desktops

In a non-virtual setup, two things need to happen to get a graphics element on the screen. First, it must be placed at a location that the screen covers. In the geometry discussion, an element at (10,10) meets this test for the first screen. One at (321, 10) does not.

The second requirement is that the graphical element must be placed on the screen. The plugin decides which screen to create a window and window surface on initially. It receives requests to move them via moveToScreen(). The element at (10,10) is not displayed at all if it is assigned to the second screen. An element can only be assigned to one screen at a time.

non-virtual  desktops

Non-virtual display of a window spanning two screens

In a virtual setup, only the first test needs to be met. An element is displayed on any and all screens which overlap the element's geometry. That means that a rectangle running from (310, 0) to (329, 99) is visible on screens 1 and 2 in our example layout.

virtual desktops

Virtual display of a window spanning two screens

Request For Comments

This design keeps the Qt side of the equation pretty simple. All windows and window surfaces are presumed to be equal and reusable. If this isn't the case, it's up to the plugin to manage any changes transparently. As always, if you see a use case that doesn't fit in with this model, let us know. We're open to constructive criticism.

Looking for an example? The VNC plugin supports both virtual and non-virtual modes. For more discussion on Qt's use of multiple screens, refer to the QDesktopWidget documentation

Blog Topics: