adonais / skylark

Skylark Editor is written in C, a high performance text/hex editor. Embedded Database-client/Redis-client/Lua-engine. You can run Lua scripts and SQL files directly.
https://sourceforge.net/projects/libportable/files/Skylark/
GNU General Public License v3.0
465 stars 46 forks source link

希望添加窗口置顶的功能 #92

Open tyspear opened 1 year ago

adonais commented 1 year ago

这个功能让我想起以前一些国内大厂家争夺用户桌面前端的恐惧, 我没有内置这个功能的想法, 但你可以用其他方式实现. 下面是一个lua脚本, 你可以把它保存到skylark安装目录的conf子目录, 比如名称为skylark_topmost.lua

local GWL_EXSTYLE = -20
local SWP_NOSIZE = 0x0001
local SWP_NOMOVE = 0x0002
local WS_EX_TOPMOST = 0x00000008

local bit = require("bit")
local ffi = require('ffi')
local euapi = ffi.load(ffi.os == "Windows" and "euapi.dll")

ffi.cdef[[
void* eu_module_hwnd(void);
void  eu_setpos_window(void*, void*, int, int, int, int, uint32_t);
intptr_t GetWindowLongPtrW(void *hwnd, int index);
]]

local function fntop(hwnd)
    local exstyle = ffi.C.GetWindowLongPtrW(hwnd, GWL_EXSTYLE)
    local flags = bit.band(exstyle, WS_EX_TOPMOST)
    return (flags ~= 0)
end

local hwnd = euapi.eu_module_hwnd()
if (hwnd ~= nil) then
  if (fntop(hwnd) == false) then
    euapi.eu_setpos_window(hwnd, ffi.cast("void *", -1), 0, 0, 0, 0, bit.bor(SWP_NOMOVE, SWP_NOSIZE))
  else
    euapi.eu_setpos_window(hwnd, ffi.cast("void *", -2), 0, 0, 0, 0, bit.bor(SWP_NOMOVE, SWP_NOSIZE))
  end
end

点击设置->自定义命令->设置运行路径, 在弹出来的窗口中填写, 名称: 总在最前 路径: conf/skylark_topmost.lua 保存, 之后你可以为这个功能菜单设一个快捷键, 打开conf/skylark_input.conf文件, 搜索"IDM_SET_LUAJIT_EXECUTE + 1", 在它下面添加一行: {bit.bor(FVIRTKEY,FALT,FSHIFT), string.byte("T"), IDM_SET_LUAJIT_EXECUTE + 2},