Skip to content

Commit

Permalink
#164 display owns layout deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Dec 23, 2024
1 parent 861ad68 commit 97815b2
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 141 deletions.
11 changes: 11 additions & 0 deletions bld/vg.supp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
fun:main
}

{
wacom DB new
Memcheck:Leak
match-leak-kinds: reachable
fun:*alloc
...
fun:libwacom_database_new
...
obj:/usr/lib/libinput.so.10.13.0
}

{
g_object_new_valist - from evdev
Memcheck:Leak
Expand Down
20 changes: 19 additions & 1 deletion inc/displ.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "xdg-output-unstable-v1.h"
// IWYU pragma: end_keep

#include "cfg.h"

enum ConfigState {
IDLE = 0,
SUCCEEDED,
Expand All @@ -16,6 +18,17 @@ enum ConfigState {
FAILED,
};

struct DisplDelta {
enum CfgElement element; // VRR_OFF indicates toggle

// only when element set
struct Head *head;

char *human;
};

extern struct LayoutDelta layout_delta;

struct Displ {
// global
struct wl_registry *registry;
Expand All @@ -34,11 +47,16 @@ struct Displ {
uint32_t zxdg_output_manager_version;
char *zxdg_output_manager_interface;

enum ConfigState config_state;
enum ConfigState state;
struct DisplDelta delta;
};

void displ_init(void);

void displ_delta_init(enum CfgElement element, struct Head *head);

void displ_delta_destroy(void);

void displ_destroy(void);

#endif // DISPL_H
9 changes: 0 additions & 9 deletions inc/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,4 @@ extern struct Lid *lid;

extern struct SList *cfg_file_paths;

// layout change in progress
// single operations for individual heads are sometimes set
struct LayoutDelta {
struct Head *head_mode;
struct Head *head_adaptive_sync;
char *brief;
};
extern struct LayoutDelta layout_delta;

#endif // GLOBAL_H
14 changes: 7 additions & 7 deletions inc/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "log.h"
#include "mode.h"

#define LEN_BRIEF 1024 * 64
#define LEN_HUMAN 1024 * 64

enum InfoEvent {
ARRIVED,
Expand All @@ -38,14 +38,14 @@ void info_user_mode_string(struct UserMode *user_mode, char *buf, size_t nbuf);

void info_mode_string(struct Mode *mode, char *buf, size_t nbuf);

// LEN_BRIEF, consumer frees
char *delta_brief(const enum ConfigState config_state, const struct SList * const heads);
// LEN_HUMAN, consumer frees
char *delta_human(const enum ConfigState state, const struct SList * const heads);

// LEN_BRIEF, consumer frees
char *delta_brief_mode(const enum ConfigState config_state, const struct Head * const head);
// LEN_HUMAN, consumer frees
char *delta_human_mode(const enum ConfigState state, const struct Head * const head);

// LEN_BRIEF, consumer frees
char *delta_brief_adaptive_sync(const enum ConfigState config_state, const struct Head * const head);
// LEN_HUMAN, consumer frees
char *delta_human_adaptive_sync(const enum ConfigState state, const struct Head * const head);

#endif // INFO_H

18 changes: 18 additions & 0 deletions src/displ.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ void displ_init(void) {
}
}

void displ_delta_init(enum CfgElement element, struct Head *head) {
displ_delta_destroy();

displ->delta.element = element;

displ->delta.head = head;
}

void displ_delta_destroy(void) {

displ->delta.element = 0;

displ->delta.head = NULL;

free(displ->delta.human);
displ->delta.human = NULL;
}

void displ_destroy(void) {

output_destroy_all();
Expand Down
7 changes: 0 additions & 7 deletions src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,3 @@ struct Lid *lid = NULL;
struct Cfg *cfg = NULL;

struct SList *cfg_file_paths = NULL;

struct LayoutDelta layout_delta = {
.head_mode = NULL,
.head_adaptive_sync = NULL,
.brief = NULL,
};

36 changes: 18 additions & 18 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ void print_heads(enum LogThreshold t, enum InfoEvent event, struct SList *heads)
}
}

char *delta_brief(const enum ConfigState config_state, const struct SList * const heads) {
char *delta_human(const enum ConfigState state, const struct SList * const heads) {
if (!heads) {
return NULL;
}

char *buf = (char*)calloc(LEN_BRIEF, sizeof(char));
char *buf = (char*)calloc(LEN_HUMAN, sizeof(char));
char *bufp = buf;

for (const struct SList *i = heads; i; i = i->nex) {
Expand All @@ -459,35 +459,35 @@ char *delta_brief(const enum ConfigState config_state, const struct SList * cons

// disable in own operation
if (head->current.enabled && !head->desired.enabled) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s disabled\n", desc_or_name);
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%s disabled\n", desc_or_name);
continue;
}

// enable in own operation
if (!head->current.enabled && head->desired.enabled) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s enabled\n", desc_or_name);
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%s enabled\n", desc_or_name);
continue;
}

if (head_current_not_desired(head)) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s\n", desc_or_name);
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%s\n", desc_or_name);

if (head->current.scale != head->desired.scale) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " scale: %.3f -> %.3f\n",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), " scale: %.3f -> %.3f\n",
wl_fixed_to_double(head->current.scale),
wl_fixed_to_double(head->desired.scale)
);
}

if (head->current.transform != head->desired.transform) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " transform: %s -> %s\n",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), " transform: %s -> %s\n",
head->current.transform ? transform_name(head->current.transform) : "none",
head->desired.transform ? transform_name(head->desired.transform) : "none"
);
}

if (head->current.x != head->desired.x || head->current.y != head->desired.y) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " position: %d,%d -> %d,%d\n",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), " position: %d,%d -> %d,%d\n",
head->current.x, head->current.y,
head->desired.x, head->desired.y
);
Expand All @@ -503,51 +503,51 @@ char *delta_brief(const enum ConfigState config_state, const struct SList * cons
return buf;
}

char *delta_brief_mode(const enum ConfigState config_state, const struct Head * const head) {
char *delta_human_mode(const enum ConfigState state, const struct Head * const head) {
if (!head) {
return NULL;
}

char *buf = (char*)calloc(LEN_BRIEF, sizeof(char));
char *buf = (char*)calloc(LEN_HUMAN, sizeof(char));
char *bufp = buf;

bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s\n ",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%s\n ",
head->description ? head->description : head->name
);

if (head->current.mode) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%dx%d@%dHz -> ",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%dx%d@%dHz -> ",
head->current.mode->width,
head->current.mode->height,
mhz_to_hz_rounded(head->current.mode->refresh_mhz)
);
} else {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "(no mode) -> ");
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "(no mode) -> ");
}

if (head->desired.mode) {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%dx%d@%dHz",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%dx%d@%dHz",
head->desired.mode->width,
head->desired.mode->height,
mhz_to_hz_rounded(head->desired.mode->refresh_mhz)
);
} else {
bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "(no mode)");
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "(no mode)");
}

return buf;
}


char *delta_brief_adaptive_sync(const enum ConfigState config_state, const struct Head * const head) {
char *delta_human_adaptive_sync(const enum ConfigState state, const struct Head * const head) {
if (!head) {
return NULL;
}

char *buf = (char*)calloc(LEN_BRIEF, sizeof(char));
char *buf = (char*)calloc(LEN_HUMAN, sizeof(char));
char *bufp = buf;

bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s\n VRR %s",
bufp += snprintf(bufp, LEN_HUMAN - (bufp - buf), "%s\n VRR %s",
head->description ? head->description : head->name,
head->desired.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off"
);
Expand Down
Loading

0 comments on commit 97815b2

Please sign in to comment.