Skip to content

Commit

Permalink
feat(spaces): add force arg for moveWindowToSpace
Browse files Browse the repository at this point in the history
Floating windows can be drawn over full screen windows so there should
be a way to move them into full screen spaces as well.
  • Loading branch information
okuuva committed Oct 13, 2022
1 parent 1bd0c18 commit 110aa0e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions extensions/spaces/libspaces.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,28 @@ static int spaces_windowsForSpace(lua_State *L) { // NOTE: wrapped in init.lua
return 1 ;
}

/// hs.spaces.moveWindowToSpace(window, spaceID) -> true | nil, error
/// hs.spaces.moveWindowToSpace(window, spaceID, force) -> true | nil, error
/// Function
/// Moves the window with the specified windowID to the space specified by spaceID.
///
/// Parameters:
/// * `window` - an integer specifying the ID of the window, or an `hs.window` object
/// * `spaceID` - an integer specifying the ID of the space
/// * `force` - a boolean specifying whether the window should be tried to move even if the spaces aren't compatible
///
/// Returns:
/// * true if the window was moved; otherwise nil and an error message.
///
/// Notes:
/// * a window can only be moved from a user space to another user space -- you cannot move the window of a full screen (or tiled) application to another space and you cannot move a window *to* the same space as a full screen application.
/// * a window can only be moved from a user space to another user space -- you cannot move the window of a full screen (or tiled) application to another space. you also cannot move a window *to* the same space as a full screen application unless `force` is set to true and even then it works for floating windows only.
static int spaces_moveWindowToSpace(lua_State *L) { // NOTE: wrapped in init.lua
LuaSkin *skin = [LuaSkin sharedWithState:L] ;
[skin checkArgs:LS_TNUMBER | LS_TINTEGER, LS_TNUMBER | LS_TINTEGER, LS_TBREAK] ;
[skin checkArgs:LS_TNUMBER | LS_TINTEGER, LS_TNUMBER | LS_TINTEGER, LS_TBOOLEAN | LS_TOPTIONAL, LS_TBREAK] ;
uint32_t wid = (uint32_t)lua_tointeger(L, 1) ;
uint64_t sid = (uint64_t)lua_tointeger(L, 2) ;
BOOL force = (lua_gettop(L) > 2) ? (BOOL)(lua_toboolean(L, 3)) : NO ;

if (SLSSpaceGetType(g_connection, sid) != 0) {
if (SLSSpaceGetType(g_connection, sid) != 0 && force == NO) {
lua_pushnil(L) ;
lua_pushfstring(L, "target space ID %d does not refer to a user space", sid) ;
return 2 ;
Expand All @@ -163,7 +165,7 @@ static int spaces_moveWindowToSpace(lua_State *L) { // NOTE: wrapped in init.lua
if (spacesList) {
if (![(__bridge NSArray *)spacesList containsObject:[NSNumber numberWithUnsignedLongLong:sid]]) {
NSNumber *sourceSpace = [(__bridge NSArray *)spacesList firstObject] ;
if (SLSSpaceGetType(g_connection, sourceSpace.unsignedLongLongValue) != 0) {
if (SLSSpaceGetType(g_connection, sourceSpace.unsignedLongLongValue) != 0 && force == NO) {
lua_pushnil(L) ;
lua_pushfstring(L, "source space for windowID %d is not a user space", wid) ;
return 2 ;
Expand Down

0 comments on commit 110aa0e

Please sign in to comment.