Update api (breaking)

This commit is contained in:
Ottatop 2023-08-12 17:43:37 -05:00
parent e4bf56026e
commit c783efa819
6 changed files with 69 additions and 101 deletions

View file

@ -66,11 +66,6 @@ function window_module.set_size(win, size) end
---@see Window.close ---@see Window.close
function window_module.close(win) end function window_module.close(win) end
---Toggle the specified window between tiled and floating.
---@tparam Window win
---@see Window.toggle_floating
function window_module.toggle_floating(win) end
---Get the specified window's size. ---Get the specified window's size.
--- ---
---@usage ---@usage
@ -126,19 +121,17 @@ function window_module.class(win) end
---@see Window.title ---@see Window.title
function window_module.title(win) end function window_module.title(win) end
---Get this window's floating status. ---Get `win`'s status.
---
---@usage
--- -- With the focused window floating...
---local win = window.get_focused()
---if win ~= nil then
--- print(window.floating(win))
---end
--- -- ...should print `true`.
---@tparam Window win ---@tparam Window win
---@treturn boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist. ---@treturn string|nil One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, `"Maximized"`, or `nil`.
---@see Window.floating ---@see Window.status
function window_module.floating(win) end function window_module.status(win) end
---Set `win`'s status.
---@tparam Window win
---@tparam string status One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, or `"Maximized"`.
---@see Window.set_status
function window_module.set_status(win, status) end
---Get whether or not this window is focused. ---Get whether or not this window is focused.
--- ---
@ -202,13 +195,6 @@ function window:toggle_tag(name, output) end
---@see WindowModule.close ---@see WindowModule.close
function window:close() end function window:close() end
---Toggle this window's floating status.
---
---@usage
---window.get_focused():toggle_floating() -- toggles the focused window between tiled and floating
---@see WindowModule.toggle_floating
function window:toggle_floating() end
---Get this window's size. ---Get this window's size.
--- ---
---@usage ---@usage
@ -254,15 +240,16 @@ function window:class() end
---@see WindowModule.title ---@see WindowModule.title
function window:title() end function window:title() end
---Get this window's floating status. ---Get this window's status.
--- ---@treturn string|nil One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, `"Maximized"`, or `nil`.
---@usage ---@see WindowModule.status
--- -- With the focused window floating... function window:status() end
---print(window.get_focused():floating())
--- -- ...should print `true`. ---Get `win`'s status.
---@treturn boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist. ---@tparam Window win
---@see WindowModule.floating ---@tparam string status One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, or `"Maximized"`.
function window:floating() end ---@see WindowModule.set_status
function window:set_status(win, status) end
---Get whether or not this window is focused. ---Get whether or not this window is focused.
--- ---

View file

@ -53,7 +53,11 @@ require("pinnacle").setup(function(pinnacle)
input.keybind({ mod_key, "Alt" }, keys.space, function() input.keybind({ mod_key, "Alt" }, keys.space, function()
local win = window.get_focused() local win = window.get_focused()
if win ~= nil then if win ~= nil then
win:toggle_floating() if win:status() == "Tiled" then
win:set_status("Floating")
elseif win:status() == "Floating" then
win:set_status("Tiled")
end
end end
end) end)
@ -63,14 +67,25 @@ require("pinnacle").setup(function(pinnacle)
end) end)
end) end)
input.keybind({ mod_key }, keys.l, function() input.keybind({ mod_key }, keys.f, function()
process.spawn("kitty") local win = window.get_focused()
if win ~= nil then
win:set_status("Fullscreen")
end
end) end)
input.keybind({ mod_key }, keys.k, function()
process.spawn("foot") input.keybind({ mod_key }, keys.m, function()
local win = window.get_focused()
if win ~= nil then
win:set_status("Maximized")
end
end) end)
input.keybind({ mod_key }, keys.j, function()
process.spawn("nautilus") input.keybind({ mod_key }, keys.t, function()
local win = window.get_focused()
if win ~= nil then
win:set_status("Tiled")
end
end) end)
-- Tags --------------------------------------------------------------------------- -- Tags ---------------------------------------------------------------------------

View file

@ -63,7 +63,7 @@
--Windows --Windows
---@field Window { window_id: WindowId|nil }? ---@field Window { window_id: WindowId|nil }?
---@field Windows { window_ids: WindowId[] }? ---@field Windows { window_ids: WindowId[] }?
---@field WindowProps { size: integer[]?, loc: integer[]?, class: string?, title: string?, floating: boolean?, focused: boolean? }? ---@field WindowProps { size: integer[]?, loc: integer[]?, class: string?, title: string?, status: StatusName?, focused: boolean? }?
--Outputs --Outputs
---@field Output { output_name: OutputName? }? ---@field Output { output_name: OutputName? }?
---@field Outputs { output_names: OutputName[] }? ---@field Outputs { output_names: OutputName[] }?

View file

@ -90,17 +90,6 @@ function window:close()
window_module.close(self) window_module.close(self)
end end
---Toggle this window's floating status.
---
---### Example
---```lua
---window.get_focused():toggle_floating() -- toggles the focused window between tiled and floating
---```
---@see WindowModule.toggle_floating — The corresponding module function
function window:toggle_floating()
window_module.toggle_floating(self)
end
---Set this window's status. Yes, this isn't a great name. ---Set this window's status. Yes, this isn't a great name.
---@param status StatusName ---@param status StatusName
function window:set_status(status) function window:set_status(status)
@ -168,18 +157,11 @@ function window:title()
return window_module.title(self) return window_module.title(self)
end end
---Get this window's floating status. ---Get this window's status.
--- ---@return StatusName|nil
---### Example ---@see WindowModule.status — The corresponding module function
---```lua function window:status()
----- With the focused window floating... return window_module.status(self)
---print(window.get_focused():floating())
----- ...should print `true`.
---```
---@return boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist.
---@see WindowModule.floating — The corresponding module function
function window:floating()
return window_module.floating(self)
end end
---Get whether or not this window is focused. ---Get whether or not this window is focused.
@ -379,17 +361,6 @@ function window_module.close(win)
}) })
end end
---Toggle the specified window between tiled and floating.
---@param win Window
---@see Window.toggle_floating — The corresponding object method
function window_module.toggle_floating(win)
SendMsg({
ToggleFloating = {
window_id = win:id(),
},
})
end
---Set `win`'s status. Yes, this is not a great name for the function. ---Set `win`'s status. Yes, this is not a great name for the function.
---@param win Window ---@param win Window
---@param status StatusName ---@param status StatusName
@ -511,28 +482,18 @@ function window_module.title(win)
return title return title
end end
---Get this window's floating status. ---Get this window's status.
---
---### Example
---```lua
----- With the focused window floating...
---local win = window.get_focused()
---if win ~= nil then
--- print(window.floating(win))
---end
----- ...should print `true`.
---```
---@param win Window ---@param win Window
---@return boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist. ---@return StatusName|nil
---@see Window.floating — The corresponding object method ---@see Window.status — The corresponding object method
function window_module.floating(win) function window_module.status(win)
local response = Request({ local response = Request({
GetWindowProps = { GetWindowProps = {
window_id = win:id(), window_id = win:id(),
}, },
}) })
local floating = response.RequestResponse.response.WindowProps.floating local status = response.RequestResponse.response.WindowProps.status
return floating return status
end end
---Get whether or not this window is focused. ---Get whether or not this window is focused.

View file

@ -209,8 +209,8 @@ pub enum RequestResponse {
loc: Option<(i32, i32)>, loc: Option<(i32, i32)>,
class: Option<String>, class: Option<String>,
title: Option<String>, title: Option<String>,
floating: Option<bool>,
focused: Option<bool>, focused: Option<bool>,
status: Option<StatusName>,
}, },
Output { Output {
output_name: Option<String>, output_name: Option<String>,

View file

@ -21,7 +21,7 @@ use crate::{
grab::resize_grab::ResizeSurfaceState, grab::resize_grab::ResizeSurfaceState,
tag::Tag, tag::Tag,
window::{ window::{
window_state::{LocationRequestState, Status}, window_state::{LocationRequestState, Status, StatusName},
WindowElement, WindowElement,
}, },
}; };
@ -374,9 +374,14 @@ impl<B: Backend> State<B> {
} }
WindowElement::X11(surface) => (Some(surface.class()), Some(surface.title())), WindowElement::X11(surface) => (Some(surface.class()), Some(surface.title())),
}); });
let floating = window let status = window.as_ref().map(|win| {
.as_ref() win.with_state(|state| match state.status {
.map(|win| win.with_state(|state| state.status.is_floating())); Status::Floating(_) => StatusName::Floating,
Status::Tiled(_) => StatusName::Tiled,
Status::Fullscreen(_) => StatusName::Fullscreen,
Status::Maximized(_) => StatusName::Maximized,
})
});
let focused = window.as_ref().and_then(|win| { let focused = window.as_ref().and_then(|win| {
self.focus_state self.focus_state
.current_focus() // TODO: actual focus .current_focus() // TODO: actual focus
@ -391,8 +396,8 @@ impl<B: Backend> State<B> {
loc, loc,
class, class,
title, title,
floating,
focused, focused,
status,
}, },
}, },
) )
@ -747,10 +752,10 @@ pub fn schedule_on_commit<F, B: Backend>(
for window in windows.iter().filter(|win| win.alive()) { for window in windows.iter().filter(|win| win.alive()) {
if window.with_state(|state| !matches!(state.loc_request_state, LocationRequestState::Idle)) if window.with_state(|state| !matches!(state.loc_request_state, LocationRequestState::Idle))
{ {
tracing::debug!( // tracing::debug!(
"window state is {:?}", // "window state is {:?}",
window.with_state(|state| state.loc_request_state.clone()) // window.with_state(|state| state.loc_request_state.clone())
); // );
data.state.loop_handle.insert_idle(|data| { data.state.loop_handle.insert_idle(|data| {
schedule_on_commit(data, windows, on_commit); schedule_on_commit(data, windows, on_commit);
}); });