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 committed Dec 11, 2023
1 parent c6efe8e commit d40a64f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
export NIX_CFLAGS_COMPILE=$(echo $NIX_CFLAGS_COMPILE | sed 's/-DQT_NO_DEBUG//')
#export QT_LOGGING_RULES="*.debug=true;qt.*.debug=false"
#export WAYLAND_DEBUG=1
export QT_PLUGIN_PATH=${makeQtpluginPath (with pkgs.qt6; [ qtbase qtdeclarative qtquick3d qtwayland ])}
export QML2_IMPORT_PATH=${makeQmlpluginPath (with pkgs.qt6; [ qtdeclarative qtquick3d ])}
export QT_PLUGIN_PATH=${makeQtpluginPath (with pkgs.qt6; [ qtbase qtdeclarative qtquick3d qtwayland qt5compat ])}
export QML2_IMPORT_PATH=${makeQmlpluginPath (with pkgs.qt6; [ qtdeclarative qtquick3d qt5compat ]
++ [ dde-nixos.packages.${system}.qt6.dtkdeclarative ] )}
export QML_IMPORT_PATH=$QML2_IMPORT_PATH
'';
};
Expand Down
57 changes: 57 additions & 0 deletions src/treeland/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -51,11 +62,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 @@ -121,6 +134,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
14 changes: 14 additions & 0 deletions src/treeland/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 d40a64f

Please sign in to comment.