From bcaad9318a68b210741ab2124aeb1a0838172656 Mon Sep 17 00:00:00 2001 From: void <> Date: Mon, 21 Oct 2024 15:29:19 +0000 Subject: [PATCH] dd target/window/slice=overlay FossilOrigin-Name: e6b4d0691a38ebb949fa3306b52458145f4d6671108fe3afa7d257b9f2298a28 --- CHANGELOG.md | 4 +++ durden/menus/target/window.lua | 17 ++++++++++- durden/tools/overlay.lua | 53 ++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa75d970..ad20d376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 0.7.0 (ongoing): +* reworked initial setup to query preferences + * global/audio extended with toggles for spatial audio and device reassignment * new tool: typer (global/input/text) @@ -86,6 +88,8 @@ minor: * overlay tool updated to respect statusbar size and side orientations +* added slice to overlay tool option for window slicing + * default HUD sort order split into two, one for browse/ and one for other paths * dropped 'simple' display mode in favor of the direct scanout control diff --git a/durden/menus/target/window.lua b/durden/menus/target/window.lua index dc628db5..3430e9cd 100644 --- a/durden/menus/target/window.lua +++ b/durden/menus/target/window.lua @@ -1092,13 +1092,21 @@ return { label = "Slice", kind = "value", description = "Slice out a window canvas region into a new window", - set = {"Active", "Passive", "Active-Dynamic", "Passive-Dynamic"}, + set = function() + local res = + {"Active", "Passive", "Active-Dynamic", "Passive-Dynamic"} + if tools_overlay_add then + table.insert(res, "Overlay") + end + return res + end, eval = function() return not mouse_blocked(); end, external_block = true, handler = function(ctx, val) local wnd = active_display().selected; local dyn = val == "Active-Dynamic" or val == "Passive-Dynamic" local act = val == "Active" or val == "Active-Dynamic" + local olay = val == "Overlay" suppl_wnd_slice(active_display().selected, function(cwin, t, l, d, r, w, h) @@ -1113,6 +1121,13 @@ return { -- the crop region accordingly so that it is centered around the mouse -- cursor setup_slice_wnd(cwin, wnd, dyn, w, h); + + if olay then + local vid = null_surface(32, 32) + image_sharestorage(cwin.canvas, vid) + cwin:destroy() + tools_overlay_add(vid, wnd) + end end); end }, diff --git a/durden/tools/overlay.lua b/durden/tools/overlay.lua index ebc8fbbf..ce59249d 100644 --- a/durden/tools/overlay.lua +++ b/durden/tools/overlay.lua @@ -41,7 +41,8 @@ local function relayout() local hr = props.height/ maxh; local outw = hr > wr and maxh * ar or maxw; local outh = hr < wr and maxw / ar or maxh; - shader_setup(active[i].vid, "simple", gconfig_get("overlay_shader")); + shader_setup(active[i].vid, + gconfig_get("overlay_shader_group"), gconfig_get("overlay_shader"), "active"); resize_image(active[i].vid, outw, outh); move_image(active[i].vid, cx, cy); cy = cy + outh; @@ -62,22 +63,14 @@ local function delete_overlay(ind) relayout(); end -local function add_overlay(wnd) --- don't permit overallocation of space - if (#active >= math.floor(1.0 / gconfig_get("overlay_size"))) then - return; - end - --- can't assume there's VIDs left - local overlay = null_surface(wnd.width, wnd.height); - if (not valid_vid(overlay)) then - return; - end - +-- slightly ugly layering violation, target/slice has a set of options and we +-- have no way of appending ourselves to that, so the slice handler checks if +-- this tool is there and, if so, exposes it that way. +function tools_overlay_add(vid, wnd) local new = { name = "overlay_hnd", - vid = overlay, - own = function(ctx, vid) return vid == overlay; end, + vid = vid, + own = function(ctx, v) return v == vid; end, -- on click, locate source window and switch to that one (if alive) click = function() for i,v in ipairs(active_display().windows) do @@ -89,24 +82,41 @@ local function add_overlay(wnd) end end, over = function() - blend_image(overlay, 1.0); + blend_image(vid, 1.0); end, out = function() - blend_image(overlay, gconfig_get("overlay_opacity")); + blend_image(vid, gconfig_get("overlay_opacity")); end, }; -- share the backend, append and place/show mouse_addlistener(new, {"click", "over", "out"}); - image_sharestorage(wnd.canvas, overlay); + table.insert(active, new); - show_image(overlay); + show_image(vid); relayout(); end +local function add_overlay(wnd) +-- don't permit overallocation of space + if (#active >= math.floor(1.0 / gconfig_get("overlay_size"))) then + return; + end + +-- can't assume there's VIDs left + local overlay = null_surface(wnd.width, wnd.height); + if (not valid_vid(overlay)) then + return; + end + + image_sharestorage(wnd.canvas, overlay); + tools_overlay_add(overlay, wnd) +end + -- config system hooks so the values get saved gconfig_register("overlay_opacity", 1.0); gconfig_register("overlay_corner", "left"); +gconfig_register("overlay_shader_group", "simple"); gconfig_register("overlay_shader", "noalpha"); gconfig_register("overlay_size", 0.1); @@ -154,10 +164,11 @@ local overlay_cfg = { return gconfig_get("overlay_shader"); end, set = function() - return shader_list({"effect", "simple"}); + return shader_list({"effect", "simple", "ui"}); end, handler = function(ctx, val) - local key, dom = shader_getkey(val, {"effect", "simple"}); + local key, dom = shader_getkey(val, {"effect", "simple", "ui"}); + gconfig_set("overlay_shader_group", dom); gconfig_set("overlay_shader", key); end },