Skip to content

Commit

Permalink
WIP: Monitor ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAdam committed Oct 23, 2023
1 parent 95b6d8c commit d9c84d6
Showing 1 changed file with 32 additions and 54 deletions.
86 changes: 32 additions & 54 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static bool randr_initialised;

static void scan_screens(Display *);
static struct monitor *monitor_by_name(const char *);
static void monitor_set_ordering(void);
static void monitor_set_coords(struct monitor *, XRRMonitorInfo);

enum monitor_tracking monitor_mode;
bool is_tracking_shared;
Expand Down Expand Up @@ -439,6 +439,26 @@ monitor_output_change(Display *dpy, XRRScreenChangeNotifyEvent *e)
monitor_check_primary();
}

static void
monitor_set_coords(struct monitor *m, XRRMonitorInfo rrm)
{
if (m == NULL)
return;

m->si->x = rrm.x;
m->si->y = rrm.y;
m->si->w = rrm.width;
m->si->h = rrm.height;
m->si->rr_output = *rrm.outputs;
if (rrm.primary > 0) {
m->flags |= MONITOR_PRIMARY;
m->was_primary = false;
} else {
m->flags &= ~MONITOR_PRIMARY;
m->was_primary = true;
}
}

static void
scan_screens(Display *dpy)
{
Expand Down Expand Up @@ -475,87 +495,45 @@ scan_screens(Display *dpy)

TAILQ_INSERT_TAIL(&screen_info_q, m->si, entry);

if (TAILQ_EMPTY(&monitor_q))
if (TAILQ_EMPTY(&monitor_q)) {
fvwm_debug(__func__, "MONITORQ EMPTY ADDING: %s", m->si->name);
TAILQ_INSERT_HEAD(&monitor_q, m, entry);
monitor_set_coords(m, rrm[i]);
}

struct monitor *m2;
TAILQ_FOREACH(m2, &monitor_q, entry) {
if (m == m2)
if (m == m2 || (strcmp(m2->si->name, name) == 0))
continue;
fvwm_debug(__func__, "LOOKING AT: %s (%d), WANT: %s (%d)",
m2->si->name, m2->si->x, m->si->name, rrm[i].x);
if (rrm[i].x < m2->si->x) {
fvwm_debug(__func__, "INSERTING: %s",
m->si->name);
TAILQ_INSERT_HEAD(&monitor_q, m, entry);
TAILQ_INSERT_BEFORE(m2, m, entry);
break;
} else {
TAILQ_INSERT_TAIL(&monitor_q, m, entry);
break;
}
}

goto set_coords;
monitor_set_coords(m, rrm[i]);
}

if ((strcmp(m->si->name, name) == 0) &&
(m->si->x != rrm[i].x || m->si->y != rrm[i].y ||
m->si->w != rrm[i].width || m->si->h != rrm[i].height)) {
if (m->flags & MONITOR_ENABLED)
m->flags |= MONITOR_CHANGED;
}

set_coords:
m->si->x = rrm[i].x;
m->si->y = rrm[i].y;
m->si->w = rrm[i].width;
m->si->h = rrm[i].height;
m->si->rr_output = *rrm[i].outputs;
if (rrm[i].primary > 0) {
m->flags |= MONITOR_PRIMARY;
m->was_primary = false;
} else {
m->flags &= ~MONITOR_PRIMARY;
m->was_primary = true;
}

XFree(name);
}

monitor_scan_edges(m);
monitor_check_primary();
monitor_set_ordering();
XRRFreeMonitors(rrm);
}

static void
monitor_set_ordering(void)
{
#if 0
struct screen_info *si, *si_next;

if (TAILQ_EMPTY(&screen_info_q_temp))
TAILQ_INIT(&screen_info_q_temp);

TAILQ_FOREACH(si, &screen_info_q, entry) {
if ((si_next = TAILQ_NEXT(si, entry)) != NULL) {
fvwm_debug(__func__, "SEEING: %s (%d), NEXT: %s (%d)", si->name, si->x, si_next->name, si_next->x);
if (si->x > si_next->x) {
TAILQ_INSERT_TAIL(&screen_info_q_temp, si, entry);
} else {

TAILQ_INSERT_HEAD(&screen_info_q_temp, si_next, entry);
}
}
}

TAILQ_FOREACH(si, &screen_info_q_temp, entry) {
fvwm_debug(__func__, "NEW: %s", si->name);
}
#endif
struct monitor *m;

TAILQ_FOREACH(m, &monitor_q, entry) {
fvwm_debug(__func__, "MON IS: %s (%d)", m->si->name, m->si->x);
}
}

void FScreenInit(Display *dpy)
{
XRRScreenResources *res = NULL;
Expand Down

0 comments on commit d9c84d6

Please sign in to comment.