1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

screenshot: add shift to perfect-square capability

This commit is contained in:
bbedward
2025-12-05 17:08:00 -05:00
parent 7f11632ea6
commit 22b2b69413
3 changed files with 57 additions and 9 deletions

View File

@@ -85,6 +85,7 @@ type RegionSelector struct {
pointerY float64 pointerY float64
preSelect Region preSelect Region
showCapturedCursor bool showCapturedCursor bool
shiftHeld bool
running bool running bool
cancelled bool cancelled bool

View File

@@ -51,13 +51,42 @@ func (r *RegionSelector) setupPointerHandlers() {
r.pointerX = e.SurfaceX r.pointerX = e.SurfaceX
r.pointerY = e.SurfaceY r.pointerY = e.SurfaceY
if r.selection.dragging { if !r.selection.dragging {
r.selection.currentX = e.SurfaceX return
r.selection.currentY = e.SurfaceY }
curX, curY := e.SurfaceX, e.SurfaceY
if r.shiftHeld {
dx := curX - r.selection.anchorX
dy := curY - r.selection.anchorY
adx, ady := dx, dy
if adx < 0 {
adx = -adx
}
if ady < 0 {
ady = -ady
}
size := adx
if ady > adx {
size = ady
}
if dx < 0 {
curX = r.selection.anchorX - size
} else {
curX = r.selection.anchorX + size
}
if dy < 0 {
curY = r.selection.anchorY - size
} else {
curY = r.selection.anchorY + size
}
}
r.selection.currentX = curX
r.selection.currentY = curY
for _, os := range r.surfaces { for _, os := range r.surfaces {
r.redrawSurface(os) r.redrawSurface(os)
} }
}
}) })
r.pointer.SetButtonHandler(func(e client.PointerButtonEvent) { r.pointer.SetButtonHandler(func(e client.PointerButtonEvent) {
@@ -93,21 +122,25 @@ func (r *RegionSelector) setupPointerHandlers() {
} }
func (r *RegionSelector) setupKeyboardHandlers() { func (r *RegionSelector) setupKeyboardHandlers() {
r.keyboard.SetModifiersHandler(func(e client.KeyboardModifiersEvent) {
r.shiftHeld = e.ModsDepressed&1 != 0
})
r.keyboard.SetKeyHandler(func(e client.KeyboardKeyEvent) { r.keyboard.SetKeyHandler(func(e client.KeyboardKeyEvent) {
if e.State != 1 { if e.State != 1 {
return return
} }
switch e.Key { switch e.Key {
case 1: // KEY_ESC case 1:
r.cancelled = true r.cancelled = true
r.running = false r.running = false
case 25: // KEY_P case 25:
r.showCapturedCursor = !r.showCapturedCursor r.showCapturedCursor = !r.showCapturedCursor
for _, os := range r.surfaces { for _, os := range r.surfaces {
r.redrawSurface(os) r.redrawSurface(os)
} }
case 28, 57: // KEY_ENTER, KEY_SPACE case 28, 57:
if r.selection.hasSelection { if r.selection.hasSelection {
r.finishSelection() r.finishSelection()
} }
@@ -163,7 +196,14 @@ func (r *RegionSelector) finishSelection() {
by2 = srcBuf.Height by2 = srcBuf.Height
} }
w, h := bx2-bx1, by2-by1 w, h := bx2-bx1+1, by2-by1+1
if r.shiftHeld && w != h {
if w < h {
h = w
} else {
w = h
}
}
if w < 1 { if w < 1 {
w = 1 w = 1
} }

View File

@@ -114,6 +114,13 @@ func (r *RegionSelector) drawOverlay(os *OutputSurface, renderBuf *ShmBuffer) {
} }
selW, selH := bx2-bx1+1, by2-by1+1 selW, selH := bx2-bx1+1, by2-by1+1
if r.shiftHeld && selW != selH {
if selW < selH {
selH = selW
} else {
selW = selH
}
}
r.drawBorder(data, stride, w, h, bx1, by1, selW, selH) r.drawBorder(data, stride, w, h, bx1, by1, selW, selH)
r.drawDimensions(data, stride, w, h, bx1, by1, selW, selH) r.drawDimensions(data, stride, w, h, bx1, by1, selW, selH)
} }