Skip to content

Commit

Permalink
config: add move-to-output action
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Mar 17, 2024
1 parent 2a517f4 commit fecfd24
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/toml-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
rustfmt:
toml-spec:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 8 additions & 1 deletion jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
crate::{
_private::{
bincode_ops,
ipc::{ClientMessage, InitMessage, Response, ServerMessage},
ipc::{ClientMessage, InitMessage, Response, ServerMessage, WorkspaceSource},
logging, Config, ConfigEntry, ConfigEntryGen, PollableId, WireMode, VERSION,
},
exec::Command,
Expand Down Expand Up @@ -421,6 +421,13 @@ impl Client {
self.send(&ClientMessage::DisablePointerConstraint { seat });
}

pub fn move_to_output(&self, workspace: WorkspaceSource, connector: Connector) {
self.send(&ClientMessage::MoveToOutput {
workspace,
connector,
});
}

pub fn set_fullscreen(&self, seat: Seat, fullscreen: bool) {
self.send(&ClientMessage::SetFullscreen { seat, fullscreen });
}
Expand Down
10 changes: 10 additions & 0 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,16 @@ pub enum ClientMessage<'a> {
SetIdle {
timeout: Duration,
},
MoveToOutput {
workspace: WorkspaceSource,
connector: Connector,
},
}

#[derive(Serialize, Deserialize, Debug)]
pub enum WorkspaceSource {
Seat(Seat),
Explicit(Workspace),
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
8 changes: 7 additions & 1 deletion jay-config/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use {
input::{acceleration::AccelProfile, capability::Capability},
keyboard::Keymap,
Axis, Direction, ModifiedKeySym, Workspace,
_private::DEFAULT_SEAT_NAME,
_private::{ipc::WorkspaceSource, DEFAULT_SEAT_NAME},
video::Connector,
},
serde::{Deserialize, Serialize},
std::time::Duration,
Expand Down Expand Up @@ -319,6 +320,11 @@ impl Seat {
pub fn disable_pointer_constraint(self) {
get!().disable_pointer_constraint(self)
}

/// Moves the currently focused workspace to another output.
pub fn move_to_output(self, connector: Connector) {
get!().move_to_output(WorkspaceSource::Seat(self), connector);
}
}

/// Returns all seats.
Expand Down
9 changes: 8 additions & 1 deletion jay-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)]

use {
crate::keyboard::ModifiedKeySym,
crate::{_private::ipc::WorkspaceSource, keyboard::ModifiedKeySym, video::Connector},
serde::{Deserialize, Serialize},
std::{
fmt::{Debug, Display, Formatter},
Expand Down Expand Up @@ -159,6 +159,13 @@ impl Workspace {
let get = get!();
get.set_workspace_capture(self, !get.get_workspace_capture(self));
}

/// Moves this workspace to another output.
///
/// This has no effect if the workspace is not currently being shown.
pub fn move_to_output(self, output: Connector) {
get!().move_to_output(WorkspaceSource::Explicit(self), output);
}
}

/// Returns the workspace with the given name.
Expand Down
5 changes: 2 additions & 3 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@ fn create_dummy_output(state: &Rc<State>) {
title_texture: Cell::new(None),
attention_requests: Default::default(),
});
dummy_workspace.output_link.set(Some(
dummy_output.workspaces.add_last(dummy_workspace.clone()),
));
*dummy_workspace.output_link.borrow_mut() =
Some(dummy_output.workspaces.add_last(dummy_workspace.clone()));
dummy_output.show_workspace(&dummy_workspace);
state.dummy_output.set(Some(dummy_output));
}
Expand Down
52 changes: 50 additions & 2 deletions src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use {
scale::Scale,
state::{ConnectorData, DeviceHandlerData, DrmDevData, OutputData, State},
theme::{Color, ThemeSized, DEFAULT_FONT},
tree::{ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase, OutputNode},
tree::{
move_ws_to_output, ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase,
OutputNode, WsMoveConfig,
},
utils::{
asyncevent::AsyncEvent,
copyhashmap::CopyHashMap,
Expand All @@ -29,7 +32,7 @@ use {
jay_config::{
_private::{
bincode_ops,
ipc::{ClientMessage, Response, ServerMessage},
ipc::{ClientMessage, Response, ServerMessage, WorkspaceSource},
PollableId, WireMode,
},
input::{
Expand Down Expand Up @@ -753,6 +756,45 @@ impl ConfigProxyHandler {
Ok(())
}

fn handle_move_to_output(
&self,
workspace: WorkspaceSource,
connector: Connector,
) -> Result<(), CphError> {
let output = self.get_output(connector)?;
let ws = match workspace {
WorkspaceSource::Explicit(ws) => {
let name = self.get_workspace(ws)?;
match self.state.workspaces.get(name.as_str()) {
Some(ws) => ws,
_ => return Ok(()),
}
}
WorkspaceSource::Seat(s) => match self.get_seat(s)?.get_output().workspace.get() {
Some(ws) => ws,
_ => return Ok(()),
},
};
if ws.is_dummy || output.node.is_dummy {
return Ok(());
}
if ws.output.get().id == output.node.id {
return Ok(());
}
let link = match &*ws.output_link.borrow() {
None => return Ok(()),
Some(l) => l.to_ref(),
};
let config = WsMoveConfig {
make_visible_if_empty: true,
source_is_destroyed: false,
};
move_ws_to_output(&link, &output.node, config);
self.state.tree_changed();
self.state.damage();
Ok(())
}

fn handle_set_idle(&self, timeout: Duration) {
self.state.idle.set_timeout(timeout);
}
Expand Down Expand Up @@ -1676,6 +1718,12 @@ impl ConfigProxyHandler {
.handle_get_input_device_devnode(device)
.wrn("get_input_device_devnode")?,
ClientMessage::SetIdle { timeout } => self.handle_set_idle(timeout),
ClientMessage::MoveToOutput {
workspace,
connector,
} => self
.handle_move_to_output(workspace, connector)
.wrn("move_to_output")?,
}
Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions src/tree/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl OutputNode {
stacked: Default::default(),
seat_state: Default::default(),
name: name.to_string(),
output_link: Cell::new(None),
output_link: Default::default(),
visible: Cell::new(false),
fullscreen: Default::default(),
visible_on_desired_output: Cell::new(false),
Expand All @@ -347,8 +347,7 @@ impl OutputNode {
title_texture: Default::default(),
attention_requests: Default::default(),
});
ws.output_link
.set(Some(self.workspaces.add_last(ws.clone())));
*ws.output_link.borrow_mut() = Some(self.workspaces.add_last(ws.clone()));
self.state.workspaces.set(name.to_string(), ws.clone());
if self.workspace.is_none() {
self.show_workspace(&ws);
Expand Down
11 changes: 8 additions & 3 deletions src/tree/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ use {
},
wire::JayWorkspaceId,
},
std::{cell::Cell, fmt::Debug, ops::Deref, rc::Rc},
std::{
cell::{Cell, RefCell},
fmt::Debug,
ops::Deref,
rc::Rc,
},
};

tree_id!(WorkspaceNodeId);
Expand All @@ -38,7 +43,7 @@ pub struct WorkspaceNode {
pub stacked: LinkedList<Rc<dyn StackedNode>>,
pub seat_state: NodeSeatState,
pub name: String,
pub output_link: Cell<Option<LinkedNode<Rc<WorkspaceNode>>>>,
pub output_link: RefCell<Option<LinkedNode<Rc<WorkspaceNode>>>>,
pub visible: Cell<bool>,
pub fullscreen: CloneCell<Option<Rc<dyn ToplevelNode>>>,
pub visible_on_desired_output: Cell<bool>,
Expand All @@ -52,7 +57,7 @@ pub struct WorkspaceNode {
impl WorkspaceNode {
pub fn clear(&self) {
self.container.set(None);
self.output_link.set(None);
*self.output_link.borrow_mut() = None;
self.fullscreen.set(None);
self.jay_workspaces.clear();
}
Expand Down
86 changes: 65 additions & 21 deletions toml-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {
status::MessageFormat,
theme::Color,
video::{GfxApi, Transform},
Axis, Direction,
Axis, Direction, Workspace,
},
std::{
error::Error,
Expand Down Expand Up @@ -53,26 +53,70 @@ pub enum SimpleCommand {

#[derive(Debug, Clone)]
pub enum Action {
ConfigureConnector { con: ConfigConnector },
ConfigureDirectScanout { enabled: bool },
ConfigureDrmDevice { dev: ConfigDrmDevice },
ConfigureIdle { idle: Duration },
ConfigureInput { input: Input },
ConfigureOutput { out: Output },
Exec { exec: Exec },
MoveToWorkspace { name: String },
Multi { actions: Vec<Action> },
SetEnv { env: Vec<(String, String)> },
SetGfxApi { api: GfxApi },
SetKeymap { map: ConfigKeymap },
SetLogLevel { level: LogLevel },
SetRenderDevice { dev: DrmDeviceMatch },
SetStatus { status: Option<Status> },
SetTheme { theme: Box<Theme> },
ShowWorkspace { name: String },
SimpleCommand { cmd: SimpleCommand },
SwitchToVt { num: u32 },
UnsetEnv { env: Vec<String> },
ConfigureConnector {
con: ConfigConnector,
},
ConfigureDirectScanout {
enabled: bool,
},
ConfigureDrmDevice {
dev: ConfigDrmDevice,
},
ConfigureIdle {
idle: Duration,
},
ConfigureInput {
input: Input,
},
ConfigureOutput {
out: Output,
},
Exec {
exec: Exec,
},
MoveToWorkspace {
name: String,
},
Multi {
actions: Vec<Action>,
},
SetEnv {
env: Vec<(String, String)>,
},
SetGfxApi {
api: GfxApi,
},
SetKeymap {
map: ConfigKeymap,
},
SetLogLevel {
level: LogLevel,
},
SetRenderDevice {
dev: DrmDeviceMatch,
},
SetStatus {
status: Option<Status>,
},
SetTheme {
theme: Box<Theme>,
},
ShowWorkspace {
name: String,
},
SimpleCommand {
cmd: SimpleCommand,
},
SwitchToVt {
num: u32,
},
UnsetEnv {
env: Vec<String>,
},
MoveToOutput {
workspace: Option<Workspace>,
output: OutputMatch,
},
}

#[derive(Debug, Clone, Default)]
Expand Down
Loading

0 comments on commit fecfd24

Please sign in to comment.