Skip to content

Commit

Permalink
fix(InitOutput.c): keep screen name and framerate across server resets.
Browse files Browse the repository at this point in the history
  • Loading branch information
twaik committed Dec 22, 2024
1 parent 3c32764 commit d239d79
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/src/main/cpp/lorie/InitOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ typedef struct {
Bool legacyDrawing;
uint8_t flip;
uint32_t width, height;
char name[1024];
uint32_t framerate;
} root;

JavaVM* vm;
Expand All @@ -125,7 +127,13 @@ typedef struct {
} lorieScreenInfo;

ScreenPtr pScreenPtr;
static lorieScreenInfo lorieScreen = { .root.width = 1280, .root.height = 1024, .dri3 = TRUE }, *pvfb = &lorieScreen;
static lorieScreenInfo lorieScreen = {
.root.width = 1280,
.root.height = 1024,
.root.framerate = 30,
.root.name = "screen",
.dri3 = TRUE,
}, *pvfb = &lorieScreen;
static char *xstartup = NULL;

#pragma clang diagnostic push
Expand Down Expand Up @@ -615,8 +623,6 @@ lorieRandRInit(ScreenPtr pScreen) {
RRCrtcPtr crtc;
RRModePtr mode;

char screenName[1024] = "screen";

if (!RRScreenInit(pScreen))
return FALSE;

Expand All @@ -628,10 +634,10 @@ lorieRandRInit(ScreenPtr pScreen) {
RRScreenSetSizeRange(pScreen, 1, 1, 32767, 32767);

if (FALSE
|| !(mode = lorieCvt(pScreen->width, pScreen->height, 30))
|| !(mode = lorieCvt(pScreen->width, pScreen->height, pvfb->root.framerate))
|| !(crtc = RRCrtcCreate(pScreen, NULL))
|| !RRCrtcGammaSetSize(crtc, 256)
|| !(output = RROutputCreate(pScreen, screenName, sizeof(screenName), NULL))
|| !(output = RROutputCreate(pScreen, pvfb->root.name, sizeof(pvfb->root.name), NULL))
|| (output->nameLength = strlen(output->name), FalseNoop())
|| !RROutputSetClones(output, NULL, 0)
|| !RROutputSetModes(output, &mode, 1, 0)
Expand Down Expand Up @@ -729,9 +735,13 @@ Bool lorieChangeWindow(unused ClientPtr pClient, void *closure) {
void lorieConfigureNotify(int width, int height, int framerate, size_t name_size, char* name) {
ScreenPtr pScreen = pScreenPtr;
RROutputPtr output = RRFirstOutput(pScreen);
framerate = framerate ? framerate : 0;

if (output && name) {
// We should save this name in pvfb to make sure the name will be restored in the case if the server is being reset.
memset(pvfb->root.name, 0, 1024);
memset(output->name, 0, 1024);
strncpy(pvfb->root.name, name, name_size < 1024 ? name_size : 1024);
strncpy(output->name, name, name_size < 1024 ? name_size : 1024);
output->name[1023] = '\0';
output->nameLength = strlen(output->name);
Expand All @@ -740,6 +750,7 @@ void lorieConfigureNotify(int width, int height, int framerate, size_t name_size
if (output && width && height && (pScreen->width != width || pScreen->height != height)) {
CARD32 mmWidth, mmHeight;
RRModePtr mode = lorieCvt(width, height, framerate);
pvfb->root.framerate = framerate;
mmWidth = ((double) (mode->mode.width)) * 25.4 / monitorResolution;
mmHeight = ((double) (mode->mode.width)) * 25.4 / monitorResolution;
RROutputSetModes(output, &mode, 1, 0);
Expand Down

0 comments on commit d239d79

Please sign in to comment.