Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions crtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st
/*
* Step 0: Check config files
* Step 1: Open the right config file
* Step 3: Apply the crtc configuration
* Step 4: Apply the screen configuration
* Step 2: Parse the crtc configuration
* Step 3: Disable all crts
* Step 4: Resize the screen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The screen size must be set AFTER altering the crtc config in any way.

So disable configs, set screen size, enable configs, set screen size

* Step 5: Apply the crtc configuration
*/

/* Step 0 */
Expand Down Expand Up @@ -58,7 +60,7 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st
}


/* Step 3 */
/* Step 2 */

vector<IniSection*> configControllers = config.getSections("CRTC");

Expand All @@ -77,7 +79,7 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st
for (int i = 0; i < resources->ncrtc; i++) {
RRCrtc *rrCrtc = (resources->crtcs + i);
for (IniSection* section : configControllers) {
RRCrtc crtc = (RRCrtc) section->getInt("crtc");
auto crtc = (RRCrtc) section->getInt("crtc");
if (*rrCrtc == crtc) {
matched++;
}
Expand Down Expand Up @@ -116,7 +118,7 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st

bool outputOff = false;

if (configOutputNames.size() == 0) {
if (configOutputNames.empty()) {
outputOff = true;
}

Expand All @@ -131,7 +133,7 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st
break;
}

CRTConfig *crtcConfig = new CRTConfig;
auto *crtcConfig = new CRTConfig;

crtcConfig->crtc = (RRCrtc) configSection->getInt("crtc");
crtcConfig->x = configSection->getInt("x");
Expand All @@ -149,43 +151,38 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st

}

/* Apply the configs */

if (!isControllerConfigValid) {
syslog(LOG_ERR, "Controller config is not valid, not committing changes to X\n");
return false;
}

/* Step 3 */

XGrabServer(display);

for (CRTConfig *controller : controllerConfigs) {

syslog(LOG_INFO, "Applying config to %4lu: mode: %4lu, outputs: %4zu, x: %4d, y: %4d\n",
controller->crtc, controller->mode, controller->noutputs, controller->x, controller->y);
syslog(LOG_INFO, "Disabling %4lu\n",
controller->crtc);

#ifndef DRYRUN

XRRSetCrtcConfig(display,
resources,
controller->crtc,
CurrentTime,
controller->x,
controller->y,
controller->mode,
controller->rotation,
controller->outputs,
(int) controller->noutputs); // cast: stack smashing: size_t (ul) copy into noutputs: int (d)
0,
0,
None,
RR_Rotate_0,
nullptr,
0);

#endif // DRYRUN

free(controller->outputs);
delete controller;

}

XUngrabServer(display);
XSync(display, 0);
XGrabServer(display);

/* Step 4 */

Expand All @@ -205,9 +202,40 @@ bool CRTControllerManager::applyConfiguration(CRTControllerManager::DockState st

#endif // DRYRUN

XUngrabServer(display);
XSync(display, 0);

/* Step 5 */

for (CRTConfig *controller : controllerConfigs) {

syslog(LOG_INFO, "Applying config to %4lu: mode: %4lu, outputs: %4zu, x: %4d, y: %4d\n",
controller->crtc, controller->mode, controller->noutputs, controller->x, controller->y);

#ifndef DRYRUN

if (controller->mode != 0) { // CRTC is to be enabled
XRRSetCrtcConfig(display,
resources,
controller->crtc,
CurrentTime,
controller->x,
controller->y,
controller->mode,
controller->rotation,
controller->outputs,
(int) controller->noutputs); // cast: stack smashing: size_t (ul) copy into noutputs: int (d)
}


#endif // DRYRUN

free(controller->outputs);
delete controller;

}

XSync(display, 0);
XUngrabServer(display);

return true;

Expand Down Expand Up @@ -239,7 +267,7 @@ bool CRTControllerManager::writeConfigToDisk(CRTControllerManager::DockState sta
int mm_width = DisplayWidthMM(display, screen);
int mm_height = DisplayHeightMM(display, screen);

IniSection *screen = new IniSection("Screen");
auto *screen = new IniSection("Screen");

screen->setInt("height", height);
screen->setInt("width", width);
Expand All @@ -252,7 +280,7 @@ bool CRTControllerManager::writeConfigToDisk(CRTControllerManager::DockState sta

for (int i = 0; i < resources->ncrtc; i++) {

IniSection *section = new IniSection("CRTC");
auto *section = new IniSection("CRTC");

RRCrtc *crtc = (resources->crtcs + i);
XRRCrtcInfo *info = XRRGetCrtcInfo(display, resources, *crtc);
Expand Down Expand Up @@ -301,7 +329,7 @@ bool CRTControllerManager::writeConfigToDisk(CRTControllerManager::DockState sta
* we need to copy the string to the heap,
* add it to the ini and free it later
*/
char *name_st = (char*) calloc(strlen(info->name) + 1, sizeof(char));
auto *name_st = (char*) calloc(strlen(info->name) + 1, sizeof(char));
strcpy(name_st, info->name);
names.push_back(name_st);

Expand Down Expand Up @@ -417,7 +445,7 @@ CRTControllerManager::OutputConfigs CRTControllerManager::getOutputConfigs(vecto

}

if (configs.mode == None && configs.outputs.size() > 0) {
if (configs.mode == None && !configs.outputs.empty()) {
syslog(LOG_ERR, "runtime error\n");
}

Expand All @@ -444,7 +472,7 @@ bool CRTControllerManager::isOutputModeSupported(RROutput output, RRMode mode) {

void CRTControllerManager::connectToX() {

display = XOpenDisplay(NULL);
display = XOpenDisplay(nullptr);

if (!display) {
syslog(LOG_ERR, "Error opening display!\n");
Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <syslog.h>

Expand All @@ -21,7 +21,7 @@ class ACPIHandler : public ACPIEventHandler {
Dock dock;

public:
void handleEvent(ACPIEvent event);
void handleEvent(ACPIEvent event) override;
};

void ACPIHandler::handleEvent(ACPIEvent event) {
Expand Down