Skip to content

Commit

Permalink
Merge branch 'clipboard'
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 9c67d0fb54e9abd11bb3a5eb79b0211e270e645ffeb1c70d1abc730d140d6bcb
  • Loading branch information
letoram committed Feb 11, 2017
2 parents 7d2ea61 + 83cb9af commit cea7723
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ By default, durden creates three named pipes (FIFO) in the ipc subdirectory of
the APPLTEMP namespace (default, same as the durden path you run, but can be
changed with the ARCAN\_APPLTEMPPATH environment variable).

The respective fifos are called (write-only: status, command) and (read-only:
The respective fifos are called (write-only: status, control) and (read-only:
output). Status can be used for providing external information, e.g. open
files, available memory, network status and have it mapped on UI components
like the status bar. The command protocol is similar to 'lemonbar' (so i3status
Expand Down
35 changes: 35 additions & 0 deletions durden/atypes/clipboard.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--
-- Clipboard- primary segment bridge
--
return {
atype = "clipboard",
default_shader = {"simple", "noalpha"},
actions = {
},
-- props will be projected upon the window during setup (unless there
-- are overridden defaults)
props = {
},
intercept = function(ctx, wnd, source, tbl)
if (gconfig_get("clipboard_access") == "none" or
gconfig_get("clipboard_access") == "passive") then
active_display():message(
"rejected clipboard injection connection attempt");
return false;
end

target_updatehandler(source,
function(src, stat)
if (stat.kind == "terminated") then
delete_image(source);
elseif (stat.kind == "message") then
CLIPBOARD:add(source, stat.message, stat.multipart);
end
end
)
return true;
end,
-- won't be used
dispatch = {
}
};
50 changes: 50 additions & 0 deletions durden/atypes/clipboard_paste.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--
-- Clipboard- primary segment bridge
--
return {
atype = "clipboard-paste",
default_shader = {"simple", "noalpha"},
actions = {
},
-- props will be projected upon the window during setup (unless there
-- are overridden defaults)
props = {
},
intercept = function(tbl, wnd, source, tbl)
if (gconfig_get("clipboard_access") == "none" or
gconfig_get("clipboard_access") == "active") then
active_display():message(
"rejected clipboard monitor connection attempt");
return false;
end

-- set us as the clipboard monitor, protect against danglers,
-- try to dump the entire history (whatever that is)
CLIPBOARD:set_monitor(function(msg, done)
if (done) then
if (wnd.destroy) then
wnd:destroy();
elseif (valid_vid(source)) then
delete_image(source);
end
return;
end
print("paste:", msg);
end);

-- only manage lifecycle, and guard against the wnd being destroyed out-of-band
target_updatehandler(source,
function(src, stat)
if (stat.kind == "terminated") then
if (wnd.destroy) then
wnd:destroy();
else
delete_image(src);
end
end
end);
return true;
end,
dispatch = {
}
};
9 changes: 9 additions & 0 deletions durden/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ local function clipboard_save(ctx, fn)
return true;
end

local function clipboard_monitor(ctx, fctx)
-- set or drop?
if (ctx.monitor) then
ctx.monitor("", true);
end
ctx.monitor = fctx;
end

local function clipboard_load(ctx, fn)
if (not resource(fn)) then
return;
Expand Down Expand Up @@ -173,6 +181,7 @@ return {
lost = clipboard_lost,
save = clipboard_save,
load = clipboard_load,
set_monitor = clipboard_monitor,
pastemodes = clipboard_pastemodes,
set_global = clipboard_setglobal,
list_local = clipboard_locals,
Expand Down
9 changes: 9 additions & 0 deletions durden/extevh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ function(wnd, source, stat)
return;
end

-- some odd archetype handlers (clipboard, ...) want to evaluate and
-- intercept the normal creation process
if (atbl.intercept) then
if (not atbl:intercept(wnd, source, stat)) then
wnd:destroy();
end
return;
end

-- note that this can be emitted multiple times, it is just the
-- segment kind that can't / wont change
wnd:set_title(stat.title);
Expand Down
7 changes: 6 additions & 1 deletion durden/gconf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ local defaults = {
enc_presilence = 0,
enc_vbr = 0,

-- SECURITY: set to :disabled to disable these features, or enable
-- SECURITY: set _path to :disabled to disable these features, or enable
-- whitelist and modify whitelist.lua to set allowed commands and paths
extcon_path = "durden",
status_path = "status",
control_path = "control",
output_path = "output",
whitelist = false,

-- SECURITY: set to passive, active, full or none depending on the default
-- access permissions to any client that requests to manage gamma or clipboard
gamma_access = "none",
clipboard_access = "none",

-- if > 0, wait n ticks before re-activating external connection path
-- (default clock, ~25 == 1s.)
extcon_rlimit = 25,
Expand Down
2 changes: 1 addition & 1 deletion durden/menus/global/audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ return {
},
{
name = "volume",
label = "Global Gain",
label = "Volume",
kind = "action",
hint = "(0..1)",
kind = "value",
Expand Down
24 changes: 22 additions & 2 deletions durden/menus/global/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ local durden_visual = {
},
{
name = "anim_in",
label = "In-Animation",
label = "Transition-In",
kind = "value",
set = {"none", "fade", "move-h", "move-v"},
initial = function() return tostring(gconfig_get("ws_transition_in")); end,
Expand All @@ -237,7 +237,7 @@ local durden_visual = {
},
{
name = "anim_out",
label = "Out-Animation",
label = "Transition-Out",
kind = "value",
set = {"none", "fade", "move-h", "move-v"},
initial = function() return tostring(gconfig_get("ws_transition_out")); end,
Expand Down Expand Up @@ -417,6 +417,26 @@ local durden_system = {
gconfig_set("whitelist", val == LBL_YES);
end
},
{
name = "bridgegamma",
label = "Gamma Bridge",
kind = "value",
initial = function() return gconfig_get("gamma_access"); end,
set = {"none", "full"},
handler = function(ctx, val)
gconfig_set("gamma_access", val);
end
},
{
name = "bridgeclip",
label = "Clipboard Bridge",
kind = "value",
initial = function() return gconfig_get("clipboard_access"); end,
set = {"none", "full", "passive", "active"},
handler = function(ctx, val)
gconfig_set("clipboard_access", val);
end
},
{
name = "statpipe",
label = "Status Pipe",
Expand Down
42 changes: 40 additions & 2 deletions durden/menus/global/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ idle_wakeup = function(key, failed)
iostatem_restore();
end,
{}, {label = string.format(
"Key (%d Failed Attempts):", failed),
failed > 0 and
"Enter Unlock Key (%d Failed Attempts):" or
"Enter Unlock Key:", failed),
password_mask = gconfig_get("passmask")
}
);
Expand Down Expand Up @@ -96,6 +98,24 @@ local function lock_value(ctx, val)
idle_setup(val, 0);
end

local function gen_appl_menu()
local res = {};
local tbl = glob_resource("*", SYS_APPL_RESOURCE);
for i,v in ipairs(tbl) do
table.insert(res, {
name = "switch_" .. tostring(i);
label = v,
dangerous = true,
kind = "action",
handler = function()
durden_shutdown();
system_collapse(v);
end,
});
end
return res;
end

local reset_query = {
{
name = "no",
Expand All @@ -113,6 +133,14 @@ local reset_query = {
system_collapse();
end
},
{
name = "switch",
label = "Switch Appl",
kind = "action",
submenu = true,
eval = function() return #glob_resource("*", SYS_APPL_RESOURCE) > 0; end,
handler = gen_appl_menu
}
};

local function query_dump()
Expand Down Expand Up @@ -271,7 +299,17 @@ local system_menu = {
handler = reset_query
},
{
name = "ouput_msg",
name = "status_msg",
label = "Status-Message",
kind = "value",
invisible = true,
validator = function(val) return true; end,
handler = function(ctx, val)
active_display():message(val and val or "");
end
},
{
name = "output_msg",
label = "IPC-Output",
kind = "value",
invisible = true,
Expand Down
2 changes: 1 addition & 1 deletion durden/menus/target/audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ return {
},
{
name ="vol_set",
label = "Gain",
label = "Volume",
hint = "(0..1)",
kind = "value",
validator = shared_valid01_float,
Expand Down
35 changes: 25 additions & 10 deletions durden/menus/target/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ local function shorten(s)
return r and r or "";
end

local function clipboard_histgen(wnd, lst)
local function clipboard_histgen(wnd, lst, promote)
local res = {};
for k, v in ipairs(lst) do
table.insert(res, {
name = "hist_" .. tostring(k),
label = string.format("%d:%s", k, string.sub(shorten(v), 1, 20)),
kind = "action",
handler = function()
local m1, m2 = dispatch_meta();
pastefun(wnd, v);
if (m1) then
if (promote) then
CLIPBOARD:set_global(v);
else
local m1, m2 = dispatch_meta();
pastefun(wnd, v);
end
end
});
Expand All @@ -82,9 +83,6 @@ local function clipboard_urls()
handler = function()
local m1, m2 = dispatch_meta();
pastefun(active_display().selected, v);
if (m1) then
CLIPBOARD:set_global(v);
end
end
});
end
Expand Down Expand Up @@ -118,11 +116,28 @@ return {
label = "History-Local",
kind = "action",
eval = function()
return valid_vid(
active_display().selected.external, TYPE_FRAMESERVER);
local wnd = active_display().selected;
return wnd.clipboard ~= nil and #CLIPBOARD:list_local(wnd.clipboard) > 0;
end,
submenu = true,
handler = clipboard_local_history
handler = function()
local wnd = active_display().selected;
return clipboard_histgen(wnd, CLIPBOARD:list_local(wnd.clipboard));
end
},
{
name = "lhistprom",
label = "Promote",
kind = "action",
eval = function()
local wnd = active_display().selected;
return wnd.clipboard ~= nil and #CLIPBOARD:list_local(wnd.clipboard) > 0;
end,
submenu = true,
handler = function()
local wnd = active_display().selected;
return clipboard_histgen(wnd, CLIPBOARD:list_local(wnd.clipboard), true);
end
},
{
name = "hist",
Expand Down
7 changes: 6 additions & 1 deletion durden/suppl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ function table.find_key_i(table, field, r)
end

function table.insert_unique_i(tbl, i, v)
if (not table.find_i(tbl, v)) then
local ind = table.find_i(tbl, v);
if (not ind) then
table.insert(tbl, i, v);
else
local cpy = tbl[i];
tbl[i] = tbl[ind];
tbl[ind] = cpy;
end
end

Expand Down
8 changes: 4 additions & 4 deletions durden/widgets/support/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ return {
end

local tbl, heights, outw, outh, asc = render_text(out);
local bdw = outw + outh;
local bdh = (heights[#heights]+outh) + outh;
local bdw = bdw > props.width and props.width or bdw;
local bdh = bdh > props.height and props.height or bdh;

if (valid_vid(tbl)) then
local bdw = outw + outh;
local bdh = (heights[#heights]+outh) + outh;
local bdw = bdw > props.width and props.width or bdw;
local bdh = bdh > props.height and props.height or bdh;
local backdrop = fill_surface(bdw, bdh, 20, 20, 20);
link_image(backdrop, anchor);
link_image(tbl, backdrop);
Expand Down

0 comments on commit cea7723

Please sign in to comment.