Skip to content

Commit

Permalink
feat: implement wlr-gamma-control and wlr-output-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
wineee authored and justforlxz committed Dec 12, 2023
1 parent 1539b3a commit b388cca
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/treeland/quick/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import TreeLand.Greeter
Item {
id :root

function getOutputDelegateFromWaylandOutput(output) {
let finder = function(props) {
if (!props.waylandOutput)
return false
if (props.waylandOutput === output)
return true
}

return QmlHelper.outputManager.getIf(outputDelegateCreator, finder)
}

WaylandServer {
id: server

Expand Down Expand Up @@ -53,11 +64,13 @@ Item {

TreeLandHelper.allowNonDrmOutputAutoChangeMode(output)
QmlHelper.outputManager.add({waylandOutput: output})
outputManagerV1.newOutput(output)
}
onOutputRemoved: function(output) {
QmlHelper.outputManager.removeIf(function(prop) {
return prop.waylandOutput === output
})
outputManagerV1.removeOutput(output)
}
onInputAdded: function(inputDevice) {
seat0.addDevice(inputDevice)
Expand Down Expand Up @@ -123,6 +136,50 @@ Item {
keyboardFocus: TreeLandHelper.getFocusSurfaceFrom(renderWindow.activeFocusItem)
}

GammaControlManager {
onGammaChanged: function(output, gamma_control, ramp_size, r, g, b) {
if (!output.setGammaLut(ramp_size, r, g, b)) {
sendFailedAndDestroy(gamma_control);
};
}
}

OutputManager {
id: outputManagerV1

onRequestTestOrApply: function(config, onlyTest) {
var states = outputManagerV1.stateListPending();
var ok = true;
for (const i in states) {
let output = states[i].output;
output.enable(states[i].enabled);
if (states[i].enabled) {
if (states[i].mode)
output.setMode(states[i].mode);
else
output.setCustomMode(states[i].custom_mode_size,
states[i].custom_mode_refresh);

output.enableAdaptiveSync(states[i].adaptive_sync_enabled);
if (!onlyTest) {
let outputDelegate = getOutputDelegateFromWaylandOutput(output);
outputDelegate.setTransform(states[i].transform)
outputDelegate.setScale(states[i].scale)
outputDelegate.setOutputPosition(states[i].x, states[i].y)
}
}

if (onlyTest) {
ok &= output.test()
output.rollback()
} else {
ok &= output.commit()
}
}
outputManagerV1.sendResult(config, ok)
}
}

CursorShapeManager { }

WaylandSocket {
Expand Down Expand Up @@ -206,9 +263,11 @@ Item {
}

Row {
// TODO: Row may break output position setting of OutputManager
id: outputRowLayout

DynamicCreatorComponent {
id: outputDelegateCreator
creator: QmlHelper.outputManager

OutputDelegate {
Expand Down
14 changes: 14 additions & 0 deletions src/treeland/quick/qml/OutputDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QtQuick.Controls
import Waylib.Server

OutputItem {
id: rootOutputItem
required property WaylandOutput waylandOutput
property OutputViewport onscreenViewport: outputViewport

Expand Down Expand Up @@ -247,4 +248,17 @@ OutputItem {
}
}
}

function setTransform(transform) {
onscreenViewport.rotationOutput(transform)
}

function setScale(scale) {
onscreenViewport.setOutputScale(scale)
}

function setOutputPosition(x, y) {
rootOutputItem.x = x;
rootOutputItem.y = y;
}
}

0 comments on commit b388cca

Please sign in to comment.