LICENSE at the root; the 103 files new in ext/src/mcde (none was in the CDE import) carry the CNCL line instead of the LGPL notice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
139 lines
5.0 KiB
C
139 lines
5.0 KiB
C
/*
|
|
* Mcde/Displays.h -- MCDE: the monitors, their arrangement and memory
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* In libDtSvc. The outputs with their modes, where they are, how they are
|
|
* turned; the file ~/.dt/displays that keeps it; the arithmetic of
|
|
* arranging (bounds, docking a dragged display to the others, mirroring):
|
|
* plain C99 in lib/DtSvc/DtUtil2/McdeDispConf.c, tested by test_displays
|
|
* (make check). Reading and setting them through RandR:
|
|
* lib/DtSvc/DtUtil2/McdeDisplays.c. Used by System Settings > Displays
|
|
* and by dtwm (plug and play).
|
|
*
|
|
* MCDE remembers a monitor, not a socket (Konrad, 2026-11-11: "mcde muss
|
|
* sich ein display und dessen position/konfiguration merken"): its id is
|
|
* made from the EDID the monitor sends (maker, product, serial number:
|
|
* "DEL-a0b7-4c4a3132"), "output-NAME" for one without (a projector of old,
|
|
* a virtual screen). A monitor that is not plugged in keeps its line, so
|
|
* that plugging it in again brings back where it was.
|
|
*
|
|
* ~/.dt/displays, one line a monitor, English keys (configuration is
|
|
* English, Konrad 2026-11-11):
|
|
*
|
|
* mirror no
|
|
* display DEL-a0b7-4c4a3132 on 1280x1024 60.02 0 0 normal primary
|
|
* display output-VGA-0 on 1024x768 60.00 1280 0 left
|
|
* display SAM-0e12-00000000 off
|
|
*/
|
|
|
|
#ifndef _Mcde_Displays_h
|
|
#define _Mcde_Displays_h
|
|
|
|
#include <stdio.h>
|
|
|
|
#define MCDE_DISP_MAX 16
|
|
#define MCDE_DISP_MODES 64
|
|
|
|
enum McdeDispRotation { MCDE_ROT_NORMAL, MCDE_ROT_LEFT, MCDE_ROT_INVERTED, MCDE_ROT_RIGHT };
|
|
|
|
typedef struct {
|
|
int w, h;
|
|
double rate; /* Hz */
|
|
} McdeDispMode;
|
|
|
|
typedef struct {
|
|
char name[32]; /* the RandR output: "DVI-0" */
|
|
char id[48]; /* the monitor: EDID id or "output-NAME" */
|
|
int connected; /* a monitor is plugged in */
|
|
int on;
|
|
int primary; /* top bar and front panel are here */
|
|
int w, h; /* the mode, not turned */
|
|
double rate;
|
|
int x, y; /* in the screen */
|
|
int rot; /* enum McdeDispRotation */
|
|
McdeDispMode modes[MCDE_DISP_MODES];
|
|
int nmodes;
|
|
/* RandR, filled by McdeDispLoad (XIDs) */
|
|
unsigned long output;
|
|
unsigned long modeId[MCDE_DISP_MODES];
|
|
unsigned short rotations; /* the rotations the CRTC can */
|
|
} McdeDisp;
|
|
|
|
typedef struct {
|
|
McdeDisp d[MCDE_DISP_MAX];
|
|
int n;
|
|
int mirror; /* all displays show the same */
|
|
} McdeDispSet;
|
|
|
|
/* "normal", "left", "inverted", "right"; -1 if none */
|
|
const char *McdeDispRotName(int rot);
|
|
int McdeDispRotParse(const char *name);
|
|
|
|
/* the size on the screen, turned */
|
|
void McdeDispSize(const McdeDisp *d, int *w, int *h);
|
|
|
|
/* the screen around the displays that are on (0 0 if none) */
|
|
void McdeDispBounds(const McdeDispSet *s, int *w, int *h);
|
|
|
|
/* the displays that are on moved so that the leftmost and topmost start
|
|
* at 0 */
|
|
void McdeDispNormalize(McdeDispSet *s);
|
|
|
|
/* display I, dropped where it is, docks to the nearest edge of another
|
|
* display that is on, without overlapping any; then McdeDispNormalize */
|
|
void McdeDispDock(McdeDispSet *s, int i);
|
|
|
|
/* the largest size every display that is on has a mode for; 0 if none */
|
|
int McdeDispCommonSize(const McdeDispSet *s, int *w, int *h);
|
|
|
|
/* mirroring: every display that is on at 0 0 with the common size (and
|
|
* the mode with the rate closest to its own); -1 if there is none */
|
|
int McdeDispMirror(McdeDispSet *s);
|
|
|
|
/* the mode of D with W x H and the rate closest to RATE; -1 if none */
|
|
int McdeDispFindMode(const McdeDisp *d, int w, int h, double rate);
|
|
|
|
/* the first display that is on and primary, else the first that is on;
|
|
* -1 if none is on */
|
|
int McdeDispPrimary(const McdeDispSet *s);
|
|
|
|
/* the id of a monitor from its EDID (at least 16 bytes); "" if it is not
|
|
* one; into BUF */
|
|
void McdeDispEdidId(const unsigned char *edid, int len, char *buf, size_t size);
|
|
|
|
/* the file: read into FILE (monitors by id and setting, no modes);
|
|
* write S (the connected monitors) and after it what REMEMBERED says of
|
|
* the monitors that are not connected now (REMEMBERED may be NULL) */
|
|
int McdeDispRead(FILE *f, McdeDispSet *file);
|
|
int McdeDispWrite(FILE *f, const McdeDispSet *s, const McdeDispSet *remembered);
|
|
|
|
/* what FILE says, put on LIVE for the monitors that are connected now and
|
|
* have the mode; the number of monitors that took it. A monitor the file
|
|
* does not name keeps what it has. */
|
|
int McdeDispMerge(McdeDispSet *live, const McdeDispSet *file);
|
|
|
|
/* ---- through RandR 1.3 (McdeDisplays.c) ---- */
|
|
|
|
struct _XDisplay;
|
|
|
|
/* ~/.dt/displays */
|
|
const char *McdeDispConfigPath(void);
|
|
|
|
/* the outputs as the server has them now (connected ones, and ones still
|
|
* on); -1 without RandR 1.3 */
|
|
int McdeDispLoad(struct _XDisplay *dpy, McdeDispSet *s);
|
|
|
|
/* S onto the server (as xrandr(1): changed CRTCs off, screen size, CRTCs
|
|
* on, the primary output); 0 on success */
|
|
int McdeDispApply(struct _XDisplay *dpy, const McdeDispSet *s);
|
|
|
|
/* ~/.dt/displays on what is plugged in: 1 applied, 0 nothing to do,
|
|
* -1 failed */
|
|
int McdeDispApplyFile(struct _XDisplay *dpy);
|
|
|
|
/* LIVE into ~/.dt/displays, the monitors not plugged in kept; 0 or -1 */
|
|
int McdeDispSave(const McdeDispSet *live);
|
|
|
|
#endif /* _Mcde_Displays_h */
|