Created
July 13, 2016 18:54
-
-
Save tomoe-mami/beabf124864c441141cd05f69a60acab to your computer and use it in GitHub Desktop.
test script for "smooth" resize a bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w = weechat | |
w.register("test", "singalaut", "0.1", "WTFPL", "", "", "") | |
function resize_bar_start_cb(_, _, tb) | |
local ptr_bar = w.bar_search(tb._bar_name) | |
if ptr_bar == "" then | |
return w.WEECHAT_RC_OK | |
end | |
-- bar_window is not bar with type window but an area of screen that is | |
-- occupied by a bar. | |
local h_bar, h_area = w.hdata_get("bar"), w.hdata_get("bar_window") | |
local ptr_area = w.hdata_pointer(h_bar, ptr_bar, "bar_window") | |
-- if empty, that means it's a not a root bar | |
-- we have to find a bar area that is inside current window first | |
if ptr_area == "" then | |
local h_win = w.hdata_get("window") | |
ptr_area = w.hdata_pointer(h_win, tb._window, "bar_windows") | |
while ptr_area ~= "" do | |
local ptr_this_bar = w.hdata_pointer(h_area, ptr_area, "bar") | |
if ptr_this_bar == ptr_bar then | |
break | |
end | |
ptr_area = w.hdata_pointer(h_area, ptr_area, "next_bar_window") | |
end | |
end | |
if ptr_area ~= "" then | |
current_bar = { | |
name = tb._bar_name, | |
pointer = ptr_bar, | |
area = ptr_area, | |
position= w.config_string(w.config_get("weechat.bar."..tb._bar_name..".position")), | |
width = w.hdata_integer(h_area, ptr_area, "width"), | |
height = w.hdata_integer(h_area, ptr_area, "height"), | |
size = w.hdata_integer(h_area, ptr_area, "current_size") | |
} | |
w.bar_set(ptr_bar, "size_max", 0) | |
end | |
return w.WEECHAT_RC_OK | |
end | |
function resize_bar_cb(_, _, tb) | |
if current_bar then | |
if tb._bar_name ~= current_bar.name then | |
current_bar = nil | |
return w.WEECHAT_RC_OK | |
end | |
local distance = 0 | |
local x, y, x2, y2 = tonumber(tb._x), tonumber(tb._y), | |
tonumber(tb._x2), tonumber(tb._y2) | |
if current_bar.position == "top" then | |
distance = y2 - y | |
elseif current_bar.position == "bottom" then | |
distance = y - y2 | |
elseif current_bar.position == "left" then | |
distance = x2 - x | |
elseif current_bar.position == "right" then | |
distance = x - x2 | |
end | |
if distance ~= 0 then | |
local new_size = current_bar.size + distance | |
w.bar_set(current_bar.pointer, "size", new_size > 0 and new_size or 0) | |
end | |
end | |
return w.WEECHAT_RC_OK | |
end | |
w.hook_hsignal("resize_bar_start", "resize_bar_start_cb", "") | |
w.hook_hsignal("resize_bar", "resize_bar_cb", "") | |
w.key_bind("mouse", { | |
["@bar(*):*-event-down"] = "hsignal:resize_bar_start", | |
["@bar(*):*-event-drag"] = "hsignal:resize_bar" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment