mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-25 09:59:21 +01:00
Update api (breaking)
This commit is contained in:
parent
e4bf56026e
commit
c783efa819
6 changed files with 69 additions and 101 deletions
|
@ -66,11 +66,6 @@ function window_module.set_size(win, size) end
|
|||
---@see Window.close
|
||||
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.
|
||||
---
|
||||
---@usage
|
||||
|
@ -126,19 +121,17 @@ function window_module.class(win) end
|
|||
---@see Window.title
|
||||
function window_module.title(win) end
|
||||
|
||||
---Get this window's floating status.
|
||||
---
|
||||
---@usage
|
||||
--- -- With the focused window floating...
|
||||
---local win = window.get_focused()
|
||||
---if win ~= nil then
|
||||
--- print(window.floating(win))
|
||||
---end
|
||||
--- -- ...should print `true`.
|
||||
---Get `win`'s status.
|
||||
---@tparam Window win
|
||||
---@treturn boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist.
|
||||
---@see Window.floating
|
||||
function window_module.floating(win) end
|
||||
---@treturn string|nil One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, `"Maximized"`, or `nil`.
|
||||
---@see Window.status
|
||||
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.
|
||||
---
|
||||
|
@ -202,13 +195,6 @@ function window:toggle_tag(name, output) end
|
|||
---@see WindowModule.close
|
||||
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.
|
||||
---
|
||||
---@usage
|
||||
|
@ -254,15 +240,16 @@ function window:class() end
|
|||
---@see WindowModule.title
|
||||
function window:title() end
|
||||
|
||||
---Get this window's floating status.
|
||||
---
|
||||
---@usage
|
||||
--- -- With the focused window floating...
|
||||
---print(window.get_focused():floating())
|
||||
--- -- ...should print `true`.
|
||||
---@treturn boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist.
|
||||
---@see WindowModule.floating
|
||||
function window:floating() end
|
||||
---Get this window's status.
|
||||
---@treturn string|nil One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, `"Maximized"`, or `nil`.
|
||||
---@see WindowModule.status
|
||||
function window:status() end
|
||||
|
||||
---Get `win`'s status.
|
||||
---@tparam Window win
|
||||
---@tparam string status One of `"Floating"`, `"Tiled"`, `"Fullscreen"`, or `"Maximized"`.
|
||||
---@see WindowModule.set_status
|
||||
function window:set_status(win, status) end
|
||||
|
||||
---Get whether or not this window is focused.
|
||||
---
|
||||
|
|
|
@ -53,7 +53,11 @@ require("pinnacle").setup(function(pinnacle)
|
|||
input.keybind({ mod_key, "Alt" }, keys.space, function()
|
||||
local win = window.get_focused()
|
||||
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)
|
||||
|
||||
|
@ -63,14 +67,25 @@ require("pinnacle").setup(function(pinnacle)
|
|||
end)
|
||||
end)
|
||||
|
||||
input.keybind({ mod_key }, keys.l, function()
|
||||
process.spawn("kitty")
|
||||
input.keybind({ mod_key }, keys.f, function()
|
||||
local win = window.get_focused()
|
||||
if win ~= nil then
|
||||
win:set_status("Fullscreen")
|
||||
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)
|
||||
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)
|
||||
|
||||
-- Tags ---------------------------------------------------------------------------
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
--Windows
|
||||
---@field Window { window_id: WindowId|nil }?
|
||||
---@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
|
||||
---@field Output { output_name: OutputName? }?
|
||||
---@field Outputs { output_names: OutputName[] }?
|
||||
|
|
|
@ -90,17 +90,6 @@ function window:close()
|
|||
window_module.close(self)
|
||||
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.
|
||||
---@param status StatusName
|
||||
function window:set_status(status)
|
||||
|
@ -168,18 +157,11 @@ function window:title()
|
|||
return window_module.title(self)
|
||||
end
|
||||
|
||||
---Get this window's floating status.
|
||||
---
|
||||
---### Example
|
||||
---```lua
|
||||
----- With the focused window floating...
|
||||
---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)
|
||||
---Get this window's status.
|
||||
---@return StatusName|nil
|
||||
---@see WindowModule.status — The corresponding module function
|
||||
function window:status()
|
||||
return window_module.status(self)
|
||||
end
|
||||
|
||||
---Get whether or not this window is focused.
|
||||
|
@ -379,17 +361,6 @@ function window_module.close(win)
|
|||
})
|
||||
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.
|
||||
---@param win Window
|
||||
---@param status StatusName
|
||||
|
@ -511,28 +482,18 @@ function window_module.title(win)
|
|||
return title
|
||||
end
|
||||
|
||||
---Get this window's floating 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`.
|
||||
---```
|
||||
---Get this window's status.
|
||||
---@param win Window
|
||||
---@return boolean|nil floating `true` if it's floating, `false` if it's tiled, or nil if it doesn't exist.
|
||||
---@see Window.floating — The corresponding object method
|
||||
function window_module.floating(win)
|
||||
---@return StatusName|nil
|
||||
---@see Window.status — The corresponding object method
|
||||
function window_module.status(win)
|
||||
local response = Request({
|
||||
GetWindowProps = {
|
||||
window_id = win:id(),
|
||||
},
|
||||
})
|
||||
local floating = response.RequestResponse.response.WindowProps.floating
|
||||
return floating
|
||||
local status = response.RequestResponse.response.WindowProps.status
|
||||
return status
|
||||
end
|
||||
|
||||
---Get whether or not this window is focused.
|
||||
|
|
|
@ -209,8 +209,8 @@ pub enum RequestResponse {
|
|||
loc: Option<(i32, i32)>,
|
||||
class: Option<String>,
|
||||
title: Option<String>,
|
||||
floating: Option<bool>,
|
||||
focused: Option<bool>,
|
||||
status: Option<StatusName>,
|
||||
},
|
||||
Output {
|
||||
output_name: Option<String>,
|
||||
|
|
23
src/state.rs
23
src/state.rs
|
@ -21,7 +21,7 @@ use crate::{
|
|||
grab::resize_grab::ResizeSurfaceState,
|
||||
tag::Tag,
|
||||
window::{
|
||||
window_state::{LocationRequestState, Status},
|
||||
window_state::{LocationRequestState, Status, StatusName},
|
||||
WindowElement,
|
||||
},
|
||||
};
|
||||
|
@ -374,9 +374,14 @@ impl<B: Backend> State<B> {
|
|||
}
|
||||
WindowElement::X11(surface) => (Some(surface.class()), Some(surface.title())),
|
||||
});
|
||||
let floating = window
|
||||
.as_ref()
|
||||
.map(|win| win.with_state(|state| state.status.is_floating()));
|
||||
let status = window.as_ref().map(|win| {
|
||||
win.with_state(|state| match state.status {
|
||||
Status::Floating(_) => StatusName::Floating,
|
||||
Status::Tiled(_) => StatusName::Tiled,
|
||||
Status::Fullscreen(_) => StatusName::Fullscreen,
|
||||
Status::Maximized(_) => StatusName::Maximized,
|
||||
})
|
||||
});
|
||||
let focused = window.as_ref().and_then(|win| {
|
||||
self.focus_state
|
||||
.current_focus() // TODO: actual focus
|
||||
|
@ -391,8 +396,8 @@ impl<B: Backend> State<B> {
|
|||
loc,
|
||||
class,
|
||||
title,
|
||||
floating,
|
||||
focused,
|
||||
status,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -747,10 +752,10 @@ pub fn schedule_on_commit<F, B: Backend>(
|
|||
for window in windows.iter().filter(|win| win.alive()) {
|
||||
if window.with_state(|state| !matches!(state.loc_request_state, LocationRequestState::Idle))
|
||||
{
|
||||
tracing::debug!(
|
||||
"window state is {:?}",
|
||||
window.with_state(|state| state.loc_request_state.clone())
|
||||
);
|
||||
// tracing::debug!(
|
||||
// "window state is {:?}",
|
||||
// window.with_state(|state| state.loc_request_state.clone())
|
||||
// );
|
||||
data.state.loop_handle.insert_idle(|data| {
|
||||
schedule_on_commit(data, windows, on_commit);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue