xsecurelock  1.7.0
XSecureLock is an X11 screen lock utility.
Macros | Functions
monitors.c File Reference
#include "monitors.h"
#include <X11/Xlib.h>
#include <stdlib.h>
#include <string.h>
#include "../env_settings.h"
#include "../logging.h"

Macros

#define CLAMP(x, mi, ma)   ((x) < (mi) ? (mi) : (x) > (ma) ? (ma) : (x))
 

Functions

static int CompareMonitors (const void *a, const void *b)
 
static int IntervalsOverlap (int astart, int asize, int bstart, int bsize)
 
static void AddMonitor (Monitor *out_monitors, size_t *num_monitors, size_t max_monitors, int x, int y, int w, int h)
 
static void GetMonitorsGuess (const XWindowAttributes *xwa, Monitor *out_monitors, size_t *out_num_monitors, size_t max_monitors)
 
size_t GetMonitors (Display *dpy, Window window, Monitor *out_monitors, size_t max_monitors)
 Queries the current monitor configuration. More...
 
void SelectMonitorChangeEvents (Display *dpy, Window window)
 Enable receiving monitor change events for the given display at w. More...
 
int IsMonitorChangeEvent (Display *dpy, int type)
 Returns the event type that indicates a change to the monitor configuration. More...
 

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   x,
  mi,
  ma 
)    ((x) < (mi) ? (mi) : (x) > (ma) ? (ma) : (x))

Function Documentation

◆ AddMonitor()

static void AddMonitor ( Monitor out_monitors,
size_t *  num_monitors,
size_t  max_monitors,
int  x,
int  y,
int  w,
int  h 
)
static

◆ CompareMonitors()

static int CompareMonitors ( const void *  a,
const void *  b 
)
static

◆ GetMonitors()

size_t GetMonitors ( Display *  dpy,
Window  window,
Monitor out_monitors,
size_t  max_monitors 
)

Queries the current monitor configuration.

Note: out_monitors will be zero padded and sorted in some deterministic order so memcmp can be used to check if the monitor configuration has actually changed.

Parameters
dpyThe current display.
wThe window this application intends to draw in.
out_monitorsA pointer to an array that will receive the monitor configuration (in coordinates relative and clipped to the window w.
max_monitorsThe size of the array.
Returns
The number of monitors returned in the array.

◆ GetMonitorsGuess()

static void GetMonitorsGuess ( const XWindowAttributes *  xwa,
Monitor out_monitors,
size_t *  out_num_monitors,
size_t  max_monitors 
)
static

◆ IntervalsOverlap()

static int IntervalsOverlap ( int  astart,
int  asize,
int  bstart,
int  bsize 
)
static

◆ IsMonitorChangeEvent()

int IsMonitorChangeEvent ( Display *  dpy,
int  type 
)

Returns the event type that indicates a change to the monitor configuration.

Parameters
dpyThe current display.
typeThe received event type.
Returns
1 if the received event is a monitor change event and GetMonitors should be called, or 0 otherwise.

◆ SelectMonitorChangeEvents()

void SelectMonitorChangeEvents ( Display *  dpy,
Window  window 
)

Enable receiving monitor change events for the given display at w.