Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/cli/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ pub struct JsonTreeNode<'a> {
#[serde(skip_serializing_if = "is_none")]
pub workspace: Option<&'a str>,
#[serde(skip_serializing_if = "is_none")]
pub workspace_type: Option<&'a str>,
#[serde(skip_serializing_if = "is_none")]
pub toplevel_id: Option<&'a str>,
#[serde(skip_serializing_if = "is_none")]
pub placeholder_for: Option<&'a str>,
Expand Down
7 changes: 7 additions & 0 deletions src/cli/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct Node {
x_instance: Option<String>,
x_role: Option<String>,
workspace: Option<String>,
workspace_type: Option<String>,
placeholder_for: Option<String>,
floating: bool,
visible: bool,
Expand Down Expand Up @@ -212,6 +213,10 @@ impl Query<'_> {
last!(d, n);
n.workspace = Some(event.name.to_string());
});
WorkspaceType::handle(tl, id, d.clone(), |d, event| {
last!(d, n);
n.workspace_type = Some(event.ty.to_string());
});
ToplevelId::handle(tl, id, d.clone(), |d, event| {
last!(d, n);
n.toplevel_id = Some(event.id.to_string());
Expand Down Expand Up @@ -340,6 +345,7 @@ fn make_json_tree_node<'b>(clients: &'b AHashMap<u64, Client>, node: &'b Node) -
ty: JsonTreeNodeType(node.ty),
output: node.output.as_deref(),
workspace: node.workspace.as_deref(),
workspace_type: node.workspace_type.as_deref(),
toplevel_id: node.toplevel_id.as_deref(),
placeholder_for: node.placeholder_for.as_deref(),
position,
Expand Down Expand Up @@ -410,6 +416,7 @@ impl Printer {
}
if node.ty == TREE_TY_WORKSPACE {
opt!(workspace, "name");
opt!(workspace_type, "workspace-type");
}
opt!(toplevel_id, "id");
opt!(placeholder_for, "placeholder-for");
Expand Down
87 changes: 55 additions & 32 deletions src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use {
theme::{ThemeColor, ThemeSized},
tree::{
ContainerSplit, OutputNode, OutputNodeOrPersistent, TearingMode, TileState,
ToplevelData, ToplevelIdentifier, ToplevelNode, VrrMode, WorkspaceNode, WsMoveConfig,
move_ws_to_output, toplevel_create_split, toplevel_parent_container,
ToplevelData, ToplevelIdentifier, ToplevelNode, VrrMode, WorkspaceNode, WorkspaceType,
WsMoveConfig, move_ws_to_output, toplevel_create_split, toplevel_parent_container,
toplevel_set_floating, toplevel_set_workspace,
},
utils::{
Expand Down Expand Up @@ -106,8 +106,8 @@ pub(super) struct ConfigProxyHandler {
pub bufs: Stack<Vec<u8>>,

pub workspace_ids: NumCell<u64>,
pub workspaces_by_name: CopyHashMap<Rc<String>, u64>,
pub workspaces_by_id: CopyHashMap<u64, Rc<String>>,
pub workspaces_by_name: CopyHashMap<String, Rc<ConfigWorkspace>>,
pub workspaces_by_id: CopyHashMap<u64, Rc<ConfigWorkspace>>,

pub timer_ids: NumCell<u64>,
pub timers_by_name: CopyHashMap<Rc<String>, Rc<TimerData>>,
Expand Down Expand Up @@ -157,6 +157,12 @@ pub(super) struct ConfigProxyHandler {
>,
}

pub struct ConfigWorkspace {
id: u64,
name: String,
ty: Cell<WorkspaceType>,
}

pub struct Pollable {
write_trigger: Rc<AsyncEvent>,
_write_future: SpawnedFuture<()>,
Expand Down Expand Up @@ -238,16 +244,23 @@ impl ConfigProxyHandler {
self.next_id.fetch_add(1)
}

fn get_workspace_by_name(&self, name: &String) -> Workspace {
fn get_workspace_by_name(&self, name: &String, ty: WorkspaceType) -> Workspace {
let id = match self.workspaces_by_name.get(name) {
None => {
let id = self.workspace_ids.fetch_add(1);
let name = Rc::new(name.clone());
self.workspaces_by_name.set(name.clone(), id);
self.workspaces_by_id.set(id, name);
let ws = Rc::new(ConfigWorkspace {
id,
name: name.to_string(),
ty: Cell::new(ty),
});
self.workspaces_by_name.set(name.clone(), ws.clone());
self.workspaces_by_id.set(id, ws);
id
}
Some(id) => id,
Some(ws) => {
ws.ty.set(ty);
ws.id
}
};
Workspace(id)
}
Expand Down Expand Up @@ -572,7 +585,7 @@ impl ConfigProxyHandler {
fn handle_get_workspaces(&self) {
let mut workspaces = vec![];
for ws in self.state.workspaces.lock().values() {
workspaces.push(self.get_workspace_by_name(&ws.name));
workspaces.push(self.get_workspace_by_name(&ws.name, ws.ty));
}
self.respond(Response::GetWorkspaces { workspaces });
}
Expand Down Expand Up @@ -683,7 +696,7 @@ impl ConfigProxyHandler {
Ok(())
}

fn get_workspace(&self, ws: Workspace) -> Result<Rc<String>, CphError> {
fn get_workspace(&self, ws: Workspace) -> Result<Rc<ConfigWorkspace>, CphError> {
match self.workspaces_by_id.get(&ws.0) {
Some(ws) => Ok(ws),
_ => Err(CphError::WorkspaceDoesNotExist(ws)),
Expand All @@ -692,7 +705,7 @@ impl ConfigProxyHandler {

fn get_existing_workspace(&self, ws: Workspace) -> Result<Option<Rc<WorkspaceNode>>, CphError> {
self.get_workspace(ws)
.map(|ws| self.state.workspaces.get(&*ws))
.map(|ws| self.state.workspaces.get(&ws.name))
}

fn get_device_handler_data(
Expand Down Expand Up @@ -935,7 +948,7 @@ impl ConfigProxyHandler {

fn handle_get_workspace(&self, name: &str) {
self.respond(Response::GetWorkspace {
workspace: self.get_workspace_by_name(&name.to_owned()),
workspace: self.get_workspace_by_name(&name.to_owned(), WorkspaceType::Normal),
});
}

Expand Down Expand Up @@ -1042,7 +1055,7 @@ impl ConfigProxyHandler {
if !output.is_dummy
&& let Some(ws) = output.workspace()
{
workspace = self.get_workspace_by_name(&ws.name);
workspace = self.get_workspace_by_name(&ws.name, ws.ty);
}
self.respond(Response::GetSeatCursorWorkspace { workspace });
Ok(())
Expand All @@ -1052,7 +1065,7 @@ impl ConfigProxyHandler {
let seat = self.get_seat(seat)?;
let mut workspace = Workspace(0);
if let Some(ws) = seat.get_keyboard_workspace() {
workspace = self.get_workspace_by_name(&ws.name);
workspace = self.get_workspace_by_name(&ws.name, ws.ty);
}
self.respond(Response::GetSeatKeyboardWorkspace { workspace });
Ok(())
Expand All @@ -1065,9 +1078,10 @@ impl ConfigProxyHandler {
output: Option<Connector>,
) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
let name = self.get_workspace(ws)?;
let ws = self.get_workspace(ws)?;
let output = output.map(|o| self.get_output_node(o)).transpose()?;
self.state.show_workspace(&seat, &name, output);
self.state
.show_workspace(&seat, &ws.name, ws.ty.get(), output);
Ok(())
}

Expand Down Expand Up @@ -1115,12 +1129,12 @@ impl ConfigProxyHandler {
};
Ok(Some(o))
};
let name = self.get_workspace(workspace)?;
let ws = self.get_workspace(workspace)?;
let mut seat = None;
if focus {
seat = get_seat(&mut seat_opt)?;
}
if let Some(ws) = self.state.workspaces.get(&*name) {
if let Some(ws) = self.state.workspaces.get(&ws.name) {
let mut output = ws.output.get();
if move_to_connector && let Some(o) = get_output(&mut seat_opt)? {
output = o;
Expand All @@ -1138,7 +1152,9 @@ impl ConfigProxyHandler {
};
Params {
move_: false,
ws: output.create_workspace(&name),
ws: match ws.ty.get() {
WorkspaceType::Normal => output.create_normal_workspace(&ws.name),
},
output,
seat,
}
Expand Down Expand Up @@ -1168,23 +1184,29 @@ impl ConfigProxyHandler {

fn handle_set_seat_workspace(&self, seat: Seat, ws: Workspace) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
let name = self.get_workspace(ws)?;
let workspace = match self.state.workspaces.get(name.deref()) {
let ws = self.get_workspace(ws)?;
let workspace = match self.state.workspaces.get(&ws.name) {
Some(ws) => ws,
_ => seat.get_fallback_output().create_workspace(name.deref()),
_ => match ws.ty.get() {
WorkspaceType::Normal => {
seat.get_fallback_output().create_normal_workspace(&ws.name)
}
},
};
seat.set_workspace(&workspace);
Ok(())
}

fn handle_set_window_workspace(&self, window: Window, ws: Workspace) -> Result<(), CphError> {
let window = self.get_window(window)?;
let name = self.get_workspace(ws)?;
let workspace = match self.state.workspaces.get(name.deref()) {
let ws = self.get_workspace(ws)?;
let workspace = match self.state.workspaces.get(&ws.name) {
Some(ws) => ws,
_ => match window.node_output() {
Some(o) => o.create_workspace(name.deref()),
_ => return Ok(()),
_ => match ws.ty.get() {
WorkspaceType::Normal => match window.node_output() {
Some(o) => o.create_normal_workspace(&ws.name),
_ => return Ok(()),
},
},
};
toplevel_set_workspace(&self.state, window, &workspace);
Expand Down Expand Up @@ -1731,7 +1753,8 @@ impl ConfigProxyHandler {
let workspace = output
.workspace
.get()
.map_or(Workspace(0), |ws| self.get_workspace_by_name(&ws.name));
.map(|ws| self.get_workspace_by_name(&ws.name, ws.ty))
.unwrap_or(Workspace(0));
self.respond(Response::GetConnectorActiveWorkspace { workspace });
Ok(())
}
Expand All @@ -1741,7 +1764,7 @@ impl ConfigProxyHandler {
let workspaces = output
.workspaces
.iter()
.map(|ws| self.get_workspace_by_name(&ws.name))
.map(|ws| self.get_workspace_by_name(&ws.name, ws.ty))
.collect::<Vec<_>>();
self.respond(Response::GetConnectorWorkspaces { workspaces });
Ok(())
Expand Down Expand Up @@ -2342,7 +2365,7 @@ impl ConfigProxyHandler {
WindowCriterionIpc::Fullscreen => mgr.fullscreen(),
WindowCriterionIpc::JustMapped => mgr.just_mapped(),
WindowCriterionIpc::Workspace(w) => mgr.workspace(CritLiteralOrRegex::Literal(
self.get_workspace(*w)?.to_string(),
self.get_workspace(*w)?.name.clone(),
)),
WindowCriterionIpc::ContentTypes(t) => mgr.content_type(*t),
};
Expand Down Expand Up @@ -2813,7 +2836,7 @@ impl ConfigProxyHandler {
.tl_data()
.workspace
.get()
.map(|ws| self.get_workspace_by_name(&ws.name))
.map(|ws| self.get_workspace_by_name(&ws.name, ws.ty))
.unwrap_or(Workspace(0));
self.respond(Response::GetWindowWorkspace { workspace });
Ok(())
Expand Down
29 changes: 25 additions & 4 deletions src/control_center/cc_workspaces.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use {
crate::{
control_center::{ControlCenterInner, bool, grid, row},
control_center::{ControlCenterInner, bool, grid, label, row},
state::State,
tree::Node,
tree::{Node, WorkspaceType},
},
egui::{CollapsingHeader, ComboBox, Ui},
egui::{CollapsingHeader, ComboBox, TextFormat, Ui, text::LayoutJob},
std::rc::Rc,
};

Expand Down Expand Up @@ -32,8 +32,29 @@ impl WorkspacesPane {
outputs.sort_unstable_by_key(|o| o.global.connector.name.clone());
for ws in ws {
let output = ws.output.get();
CollapsingHeader::new(&*ws.name).show(ui, |ui| {
let ty = match ws.ty {
WorkspaceType::Normal => "Normal",
};
let mut layout_job = LayoutJob::default();
layout_job.append(
ty,
0.0,
TextFormat {
color: ui.style().visuals.widgets.inactive.text_color(),
..Default::default()
},
);
layout_job.append(
&ws.name,
10.0,
TextFormat {
color: ui.style().visuals.widgets.active.text_color(),
..Default::default()
},
);
CollapsingHeader::new(layout_job).show(ui, |ui| {
grid(ui, "settings", |ui| {
label(ui, "Type", ty);
row(ui, "Position", |ui| {
let p = ws.position.get();
if output.is_dummy {
Expand Down
2 changes: 1 addition & 1 deletion src/ifs/jay_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ global_base!(JayCompositorGlobal, JayCompositor, JayCompositorError);

impl Global for JayCompositorGlobal {
fn version(&self) -> u32 {
30
31
}

fn required_caps(&self) -> ClientCaps {
Expand Down
22 changes: 20 additions & 2 deletions src/ifs/jay_tree_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use {
tree::{
self, ContainerNode, DisplayNode, FloatNode, Node, NodeVisitor, OutputNode,
PlaceholderNode, ToplevelData, ToplevelIdentifier, ToplevelNodeBase, ToplevelType,
WorkspaceNode,
WorkspaceNode, WorkspaceType,
},
utils::{opaque::OpaqueError, opt::Opt},
wire::{JayTreeQueryId, jay_tree_query::*},
wire::{
JayTreeQueryId,
jay_tree_query::{self, *},
},
Comment thread
mahkoh marked this conversation as resolved.
},
isnt::std_1::primitive::IsntStrExt,
std::{
Expand All @@ -46,6 +49,8 @@ pub const TREE_TY_LOCK_SURFACE: u32 = 11;

const CONTENT_TYPE_SINCE: Version = Version(20);

const WORKSPACE_TYPE_SINCE: Version = Version(31);

pub struct JayTreeQuery {
pub id: JayTreeQueryId,
pub client: Rc<Client>,
Expand Down Expand Up @@ -124,6 +129,16 @@ impl JayTreeQuery {
});
}

fn send_workspace_type(&self, ty: WorkspaceType) {
let ty = match ty {
WorkspaceType::Normal => "normal",
};
self.client.event(jay_tree_query::WorkspaceType {
self_id: self.id,
ty,
});
}

fn send_output_name(&self, name: &str) {
self.client.event(OutputName {
self_id: self.id,
Expand Down Expand Up @@ -417,6 +432,9 @@ impl tree::NodeVisitorBase for Visitor<'_> {
if !o.is_dummy {
s.send_output_name(&o.global.connector.name);
}
if self.0.version >= WORKSPACE_TYPE_SINCE {
s.send_workspace_type(node.ty);
}
for stacked in node.stacked.iter() {
if stacked.stacked_is_xdg_popup() {
continue;
Expand Down
Loading
Loading