mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-29 22:42:11 -04:00
fix(Screenshot): allow region capture over shell overlays
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/clipboard"
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/clipboard"
|
||||||
@@ -179,9 +181,39 @@ func getScreenshotConfig(mode screenshot.Mode) screenshot.Config {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setPopoutScreenshotMode toggles the shell handshake so popouts drop their keyboard grab during region select. Best-effort.
|
||||||
|
func setPopoutScreenshotMode(begin bool) {
|
||||||
|
fn := "end"
|
||||||
|
if begin {
|
||||||
|
fn = "begin"
|
||||||
|
}
|
||||||
|
cmdArgs := []string{"ipc"}
|
||||||
|
if pid, ok := getFirstDMSPID(); ok {
|
||||||
|
cmdArgs = append(cmdArgs, "--pid", strconv.Itoa(pid))
|
||||||
|
} else {
|
||||||
|
if err := findConfig(nil, nil); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if qsHasAnyDisplay() {
|
||||||
|
cmdArgs = append(cmdArgs, "--any-display")
|
||||||
|
}
|
||||||
|
cmdArgs = append(cmdArgs, "-p", configPath)
|
||||||
|
}
|
||||||
|
cmdArgs = append(cmdArgs, "call", "screenshot", fn)
|
||||||
|
_ = exec.Command("qs", cmdArgs...).Run()
|
||||||
|
}
|
||||||
|
|
||||||
func runScreenshot(config screenshot.Config) {
|
func runScreenshot(config screenshot.Config) {
|
||||||
sc := screenshot.New(config)
|
// Region select needs the keyboard; drop popout grabs for its duration.
|
||||||
result, err := sc.Run()
|
result, err := func() (*screenshot.CaptureResult, error) {
|
||||||
|
interactive := config.Mode == screenshot.ModeRegion || config.Mode == screenshot.ModeLastRegion
|
||||||
|
if interactive {
|
||||||
|
setPopoutScreenshotMode(true)
|
||||||
|
defer setPopoutScreenshotMode(false)
|
||||||
|
}
|
||||||
|
return screenshot.New(config).Run()
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Singleton {
|
|||||||
property var currentModalsByScreen: ({})
|
property var currentModalsByScreen: ({})
|
||||||
|
|
||||||
function openModal(modal) {
|
function openModal(modal) {
|
||||||
|
PopoutManager.screenshotActive = false;
|
||||||
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
const screenName = modal.effectiveScreen?.name ?? "unknown";
|
||||||
currentModalsByScreen[screenName] = modal;
|
currentModalsByScreen[screenName] = modal;
|
||||||
modalChanged();
|
modalChanged();
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ Singleton {
|
|||||||
property var currentPopoutsByScreen: ({})
|
property var currentPopoutsByScreen: ({})
|
||||||
property var currentPopoutTriggers: ({})
|
property var currentPopoutTriggers: ({})
|
||||||
|
|
||||||
|
// Set by the screenshot IPC handshake (dms screenshot region select); cleared by end() or any popout/modal open.
|
||||||
|
property bool screenshotActive: false
|
||||||
|
|
||||||
signal popoutOpening
|
signal popoutOpening
|
||||||
signal popoutChanged
|
signal popoutChanged
|
||||||
|
|
||||||
@@ -47,6 +50,7 @@ Singleton {
|
|||||||
function showPopout(popout) {
|
function showPopout(popout) {
|
||||||
if (!popout || !popout.screen)
|
if (!popout || !popout.screen)
|
||||||
return;
|
return;
|
||||||
|
screenshotActive = false;
|
||||||
popoutOpening();
|
popoutOpening();
|
||||||
|
|
||||||
const screenName = popout.screen.name;
|
const screenName = popout.screen.name;
|
||||||
@@ -97,6 +101,7 @@ Singleton {
|
|||||||
function requestPopout(popout, tabIndex, triggerSource) {
|
function requestPopout(popout, tabIndex, triggerSource) {
|
||||||
if (!popout || !popout.screen)
|
if (!popout || !popout.screen)
|
||||||
return;
|
return;
|
||||||
|
screenshotActive = false;
|
||||||
const screenName = popout.screen.name;
|
const screenName = popout.screen.name;
|
||||||
const currentPopout = currentPopoutsByScreen[screenName];
|
const currentPopout = currentPopoutsByScreen[screenName];
|
||||||
const triggerId = triggerSource !== undefined ? triggerSource : tabIndex;
|
const triggerId = triggerSource !== undefined ? triggerSource : tabIndex;
|
||||||
|
|||||||
@@ -161,6 +161,21 @@ Item {
|
|||||||
target: "control-center"
|
target: "control-center"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IpcHandler {
|
||||||
|
// Screenshot region-select handshake
|
||||||
|
function begin(): string {
|
||||||
|
PopoutManager.screenshotActive = true;
|
||||||
|
return "SCREENSHOT_MODE_ON";
|
||||||
|
}
|
||||||
|
|
||||||
|
function end(): string {
|
||||||
|
PopoutManager.screenshotActive = false;
|
||||||
|
return "SCREENSHOT_MODE_OFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
target: "screenshot"
|
||||||
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
function resolveTabIndex(tab: string): int {
|
function resolveTabIndex(tab: string): int {
|
||||||
switch ((tab || "").toLowerCase()) {
|
switch ((tab || "").toLowerCase()) {
|
||||||
|
|||||||
@@ -689,7 +689,7 @@ Item {
|
|||||||
WlrLayershell.namespace: "dms:spotlight"
|
WlrLayershell.namespace: "dms:spotlight"
|
||||||
WlrLayershell.layer: root.effectiveLauncherLayer
|
WlrLayershell.layer: root.effectiveLauncherLayer
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None
|
WlrLayershell.keyboardFocus: PopoutManager.screenshotActive ? WlrKeyboardFocus.None : (keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None)
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
left: true
|
left: true
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ Item {
|
|||||||
WlrLayershell.namespace: "dms:spotlight"
|
WlrLayershell.namespace: "dms:spotlight"
|
||||||
WlrLayershell.layer: root.effectiveLauncherLayer
|
WlrLayershell.layer: root.effectiveLauncherLayer
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None
|
WlrLayershell.keyboardFocus: PopoutManager.screenshotActive ? WlrKeyboardFocus.None : (keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None)
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
top: true
|
top: true
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ Item {
|
|||||||
WlrLayershell.namespace: "dms:spotlight"
|
WlrLayershell.namespace: "dms:spotlight"
|
||||||
WlrLayershell.layer: root.effectiveLauncherLayer
|
WlrLayershell.layer: root.effectiveLauncherLayer
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None
|
WlrLayershell.keyboardFocus: PopoutManager.screenshotActive ? WlrKeyboardFocus.None : (keyboardActive ? (root.useHyprlandFocusGrab ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.Exclusive) : WlrKeyboardFocus.None)
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
top: true
|
top: true
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ Item {
|
|||||||
WlrLayershell.namespace: "dms:launcher-context-menu"
|
WlrLayershell.namespace: "dms:launcher-context-menu"
|
||||||
WlrLayershell.layer: WlrLayershell.Overlay
|
WlrLayershell.layer: WlrLayershell.Overlay
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: root.renderActive ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
WlrLayershell.keyboardFocus: PopoutManager.screenshotActive ? WlrKeyboardFocus.None : (root.renderActive ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None)
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
top: true
|
top: true
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ Row {
|
|||||||
WlrLayershell.namespace: "dms:control-center-widget-library"
|
WlrLayershell.namespace: "dms:control-center-widget-library"
|
||||||
WlrLayershell.layer: WlrLayershell.Overlay
|
WlrLayershell.layer: WlrLayershell.Overlay
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
WlrLayershell.keyboardFocus: PopoutManager.screenshotActive ? WlrKeyboardFocus.None : (visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None)
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
top: true
|
top: true
|
||||||
|
|||||||
@@ -981,6 +981,8 @@ BasePill {
|
|||||||
WlrLayershell.layer: root.barUsesOverlayLayer ? WlrLayershell.Overlay : WlrLayershell.Top
|
WlrLayershell.layer: root.barUsesOverlayLayer ? WlrLayershell.Overlay : WlrLayershell.Top
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (!root.menuOpen)
|
if (!root.menuOpen)
|
||||||
return WlrKeyboardFocus.None;
|
return WlrKeyboardFocus.None;
|
||||||
if (CompositorService.useHyprlandFocusGrab)
|
if (CompositorService.useHyprlandFocusGrab)
|
||||||
@@ -1449,6 +1451,8 @@ BasePill {
|
|||||||
WlrLayershell.layer: root.barUsesOverlayLayer ? WlrLayershell.Overlay : WlrLayershell.Top
|
WlrLayershell.layer: root.barUsesOverlayLayer ? WlrLayershell.Overlay : WlrLayershell.Top
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (!menuRoot.showMenu)
|
if (!menuRoot.showMenu)
|
||||||
return WlrKeyboardFocus.None;
|
return WlrKeyboardFocus.None;
|
||||||
if (CompositorService.useHyprlandFocusGrab)
|
if (CompositorService.useHyprlandFocusGrab)
|
||||||
|
|||||||
@@ -300,6 +300,8 @@ Item {
|
|||||||
}
|
}
|
||||||
WlrLayershell.exclusionMode: ExclusionMode.Ignore
|
WlrLayershell.exclusionMode: ExclusionMode.Ignore
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (root.isInteracting) {
|
if (root.isInteracting) {
|
||||||
if (CompositorService.useHyprlandFocusGrab)
|
if (CompositorService.useHyprlandFocusGrab)
|
||||||
return WlrKeyboardFocus.OnDemand;
|
return WlrKeyboardFocus.OnDemand;
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ Scope {
|
|||||||
WlrLayershell.layer: WlrLayer.Overlay
|
WlrLayershell.layer: WlrLayer.Overlay
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (!overviewScope.overviewOpen)
|
if (!overviewScope.overviewOpen)
|
||||||
return WlrKeyboardFocus.None;
|
return WlrKeyboardFocus.None;
|
||||||
if (CompositorService.useHyprlandFocusGrab)
|
if (CompositorService.useHyprlandFocusGrab)
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ Scope {
|
|||||||
WlrLayershell.layer: WlrLayer.Overlay
|
WlrLayershell.layer: WlrLayer.Overlay
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (!NiriService.inOverview)
|
if (!NiriService.inOverview)
|
||||||
return WlrKeyboardFocus.None;
|
return WlrKeyboardFocus.None;
|
||||||
if (!isActiveScreen)
|
if (!isActiveScreen)
|
||||||
|
|||||||
@@ -749,6 +749,8 @@ Item {
|
|||||||
WlrLayershell.layer: root.effectivePopoutLayer
|
WlrLayershell.layer: root.effectivePopoutLayer
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (customKeyboardFocus !== null)
|
if (customKeyboardFocus !== null)
|
||||||
return customKeyboardFocus;
|
return customKeyboardFocus;
|
||||||
if (!shouldBeVisible)
|
if (!shouldBeVisible)
|
||||||
|
|||||||
@@ -620,6 +620,8 @@ Item {
|
|||||||
WlrLayershell.layer: root.effectivePopoutLayer
|
WlrLayershell.layer: root.effectivePopoutLayer
|
||||||
WlrLayershell.exclusiveZone: -1
|
WlrLayershell.exclusiveZone: -1
|
||||||
WlrLayershell.keyboardFocus: {
|
WlrLayershell.keyboardFocus: {
|
||||||
|
if (PopoutManager.screenshotActive)
|
||||||
|
return WlrKeyboardFocus.None;
|
||||||
if (customKeyboardFocus !== null)
|
if (customKeyboardFocus !== null)
|
||||||
return customKeyboardFocus;
|
return customKeyboardFocus;
|
||||||
if (!shouldBeVisible)
|
if (!shouldBeVisible)
|
||||||
|
|||||||
Reference in New Issue
Block a user