Skip to content

Commit

Permalink
dd target/window/slice=overlay
Browse files Browse the repository at this point in the history
FossilOrigin-Name: e6b4d0691a38ebb949fa3306b52458145f4d6671108fe3afa7d257b9f2298a28
  • Loading branch information
void committed Oct 21, 2024
1 parent 12dbbe9 commit bcaad93
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion durden/menus/target/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
},
Expand Down
53 changes: 32 additions & 21 deletions durden/tools/overlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit bcaad93

Please sign in to comment.