Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawin: Add support for the desktop layer. #3750

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/common/wibox.ldoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
-- @tparam[opt=false] boolean ontop
-- @propemits false false

--- Below other windows and widgets.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does and widgets refer to? Wiboxes/drawins are not ordered relative to widgets, are they? I'd just leave that part out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would probably be better to say and wiboxes or and drawins, or, as you said, just leave that part out entirely. not sure which one would be better. my bad for getting the terminology wrong lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now thinking about it, and drawins is probably not optimal, since there's not many places where drawins are explained in the docs, unlike wiboxes, which have a dedicated page.

--
-- @baseclass wibox
-- @property desktop
-- @tparam[opt=false] boolean desktop
-- @propemits false false

--- The mouse cursor.
--
-- @baseclass wibox
Expand Down
1 change: 1 addition & 0 deletions lib/wibox/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ local function setup_signals(w)
clone_signal("property::cursor")
clone_signal("property::height")
clone_signal("property::ontop")
clone_signal("property::desktop")
clone_signal("property::opacity")
clone_signal("property::struts")
clone_signal("property::visible")
Expand Down
48 changes: 45 additions & 3 deletions objects/drawin.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ lua_class_t drawin_class;
* @field border_width Border width.
* @field border_color Border color.
* @field ontop On top of other windows.
* @field desktop Below other windows and widgets.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. What widgets?

* @field cursor The mouse cursor.
* @field visible Visibility.
* @field opacity The opacity of the drawin, between 0 and 1.
Expand Down Expand Up @@ -101,6 +102,10 @@ lua_class_t drawin_class;
* @signal property::ontop
*/

/**
* @signal property::desktop
*/

/**
* @signal property::visible
*/
Expand Down Expand Up @@ -504,6 +509,7 @@ luaA_drawin_geometry(lua_State *L)


LUA_OBJECT_EXPORT_PROPERTY(drawin, drawin_t, ontop, lua_pushboolean)
LUA_OBJECT_EXPORT_PROPERTY(drawin, drawin_t, desktop, lua_pushboolean)
LUA_OBJECT_EXPORT_PROPERTY(drawin, drawin_t, cursor, lua_pushstring)
LUA_OBJECT_EXPORT_PROPERTY(drawin, drawin_t, visible, lua_pushboolean)

Expand Down Expand Up @@ -584,16 +590,48 @@ luaA_drawin_get_height(lua_State *L, drawin_t *drawin)
* \param drawin The drawin object.
* \return The number of elements pushed on stack.
*/
static int
luaA_drawin_set_ontop(lua_State *L, drawin_t *drawin)
void
drawin_set_ontop(lua_State *L, drawin_t *drawin, bool b)
{
bool b = luaA_checkboolean(L, -1);
if(b != drawin->ontop)
{
if(b)
drawin_set_desktop(L, drawin, false);
drawin->ontop = b;
stack_windows();
luaA_object_emit_signal(L, -3, "property::ontop", 0);
}
}

/** Set the drawin on desktop status.
* \param L The Lua VM state.
* \param drawin The drawin object.
* \return The number of elements pushed on stack.
*/
void
drawin_set_desktop(lua_State *L, drawin_t *drawin, bool b)
{
if(b != drawin->desktop)
{
if(b)
drawin_set_ontop(L, drawin, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't necessarily work. Lua could react to property::ontop and just set d.ontop = true again. Thus, you are not guaranteed that drawin->ontop = false after this call. I fear one would have to defer all signal emission until the end of this function to work-around this (not that the result would then look good from Lua's point of view, but at least that should ensure that at most one of these properties can be true at the same time).

I think these "multiple exclusive states"-thing also came up in client.c, but I don't know how it was handled there. I fear "not nicely"... :-(

Somehow this feels like it should be an enum, but that would break the magic behind LUA_OBJECT_EXPORT_PROPERTY. I don't have any good suggestion, sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these "multiple exclusive states"-thing also came up in client.c, but I don't know how it was handled there. I fear "not nicely"... :-(

correct, i mostly copied the code over from client.c..
this probably suggests that the way layers are handled should be remade entirely lol

drawin->desktop = b;
stack_windows();
luaA_object_emit_signal(L, -3, "property::desktop", 0);
}
}

static int
luaA_drawin_set_ontop(lua_State *L, drawin_t *drawin)
{
drawin_set_ontop(L, drawin, luaA_checkboolean(L, -1));
return 0;
}

static int
luaA_drawin_set_desktop(lua_State *L, drawin_t *drawin)
{
drawin_set_desktop(L, drawin, luaA_checkboolean(L, -1));
return 0;
}

Expand Down Expand Up @@ -797,6 +835,10 @@ drawin_class_setup(lua_State *L)
(lua_class_propfunc_t) luaA_drawin_set_ontop,
(lua_class_propfunc_t) luaA_drawin_get_ontop,
(lua_class_propfunc_t) luaA_drawin_set_ontop);
luaA_class_add_property(&drawin_class, "desktop",
(lua_class_propfunc_t) luaA_drawin_set_desktop,
(lua_class_propfunc_t) luaA_drawin_get_desktop,
(lua_class_propfunc_t) luaA_drawin_set_desktop);
luaA_class_add_property(&drawin_class, "cursor",
(lua_class_propfunc_t) luaA_drawin_set_cursor,
(lua_class_propfunc_t) luaA_drawin_get_cursor,
Expand Down
5 changes: 4 additions & 1 deletion objects/drawin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct drawin_t
WINDOW_OBJECT_HEADER
/** Ontop */
bool ontop;
/** Desktop */
bool desktop;
/** Visible */
bool visible;
/** Cursor */
Expand All @@ -49,7 +51,8 @@ ARRAY_FUNCS(drawin_t *, drawin, DO_NOTHING)
drawin_t * drawin_getbywin(xcb_window_t);
void drawin_refresh_pixmap_partial(drawin_t *, int16_t, int16_t, uint16_t, uint16_t);
void luaA_drawin_systray_kickout(lua_State *);

void drawin_set_ontop(lua_State *, drawin_t *, bool);
void drawin_set_desktop(lua_State *, drawin_t *, bool);
void drawin_class_setup(lua_State *);

extern lua_class_t drawin_class;
Expand Down
9 changes: 8 additions & 1 deletion stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ stack_refresh()

xcb_window_t next = XCB_NONE;

foreach(drawin, globalconf.drawins)
if ((*drawin)->desktop)
{
stack_window_above((*drawin)->window, next);
next = (*drawin)->window;
}

/* stack desktop windows */
for(window_layer_t layer = WINDOW_LAYER_DESKTOP; layer < WINDOW_LAYER_BELOW; layer++)
foreach(node, globalconf.stack)
Expand All @@ -175,7 +182,7 @@ stack_refresh()

/* first stack not ontop drawin window */
foreach(drawin, globalconf.drawins)
if(!(*drawin)->ontop)
if(!(*drawin)->ontop && !(*drawin)->desktop)
{
stack_window_above((*drawin)->window, next);
next = (*drawin)->window;
Expand Down