Skip to content

NXSystem: Display management

Sergii Stoian edited this page Jun 26, 2018 · 1 revision

Definitions

Screen - A set of displays (monitors) for a single user with one keyboard and mouse. In other words, screen is a set of hardware resources: one or more monitors, one keyboard and one mouse. Logical screen size may be bigger then sum of NXDisplays resolutions.

Xrandr’s name - Screen.

Display - Physical monitor and hardware that can be color, grayscale, or monochrome. Characterized by, resolution, refresh rate, gamma correction, brightness, contrast. Also has specific properties like: vendor and model name, serial number etc.

Xrandr’s name - Output.

View - Image visible for user on Display. It’s part of Screen and can be visible on multiple Displays (in case of clonning). View is always part of Screen but can be invisible on some Display.

Xrandr’s name - CRTC.

Concepts

While implementing display management classes (NXScreen, NXDisplay) I kept in mind some basic concepts/tasks:

  1. Avoid multiple flickering of Displays while changing resolution, state of some Display.
  2. Have layout description that can be saved and restored.
  3. Manage gamma/brightness of Display.
  4. Manage backlight of laptop internal Display.

In general it’s quite easey task because unlike ‘xrandr’ tool user can change one attribute of one Display at a time. So basic steps are:

  • change attribute of Display (resolution, state, position);
  • relayout Displays: if resolution or state were changed.

No relayout are beeing made for attribute changes like gamma/brightness or position.

Set resolution

Basically

  • isActive state left untouched
  • ‘frame.size’ is assigned a value of new resolution
  • proposedDisplayLayout shifts other Displays’ ‘frame.origin’
  • applyDisplayLayout: set resolution to Display

Current implementation

  • NXDisplay must be in active state - [NXDisplay isActive] == YES
  • Set NXDisplay’s ‘frame’ property .width and .height to desired resolution dimensions.

At this point display is active, ‘frame’ and Rsolution{Size} differs.

  • Call [NXScreen proposedDisplayLayout] to produce layout description with “frame.size” and “Resolution{Size}” synchronized.
  • Apply generated at previous step layout with -applyDisplayLayout:.

Alternate implementation

  • Get current layout description with [NXScreen currentLayout] to ‘oldLayout’.
  • Set NXDisplay’s ‘frame’ and synchronize with “Resolution{Size}”.
  • Call [NXScreen layoutWithOldLayout:oldLayout].
    • Check if NXDisplay is active - [NXDisplay isActive];
    • Check difference between [oldLayout objectForKey:NXDisplayFrameKey] and [NXDisplay frame]
    • If

Activate display

activateDisplay:

  • frame = hiddenFrame
  • hiddenFrame = {0,0,0,0}

proposedDisplayLayout Conditions for Activate:

  • isActive == NO &&
  • frame.size != {0,0} &&
  • hiddenFrame.size == {0,0}

Actions:

  • isActive = YES
  • place activated Display at position restored from ‘hiddenFrame’ to ‘frame’
  • move other Displays in right-top direction of activated Display if any

applyDisplayLayout:

  • if isActive == YES - setResolution:position:
  • if isActive == NO - setResolution:{0,0} position:{0,0}

Deactivate display

activateDisplay:

  • hiddenFrame = frame
  • frame = {0,0,0,0}

proposedDisplayLayout Conditions for Deactivate:

  • isActive == YES &&
  • hiddenFrame.size != {0,0} &&
  • frame.size == {0,0}

Actions:

  • isActive = NO
  • move other Displays in left-bottom direction of activated Display if any

applyDisplayLayout:

  • if isActive == YES - setResolution:position:
  • if isActive == NO - setResolution:{0,0} position:{0,0}

Changing displays layout

Power management

Opening/closing laptop lid. Display Blank timeout. Display switch off timeout. Display dimming timeout.

Related components

NXAlert NXMouse