Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor enhancements #258

Merged
merged 6 commits into from
Jun 21, 2024
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: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ features = [

[workspace.lints.clippy]
too_many_arguments = "allow"
new_without_default = "allow"
type_complexity = "allow"
let_and_return = "allow"

########################################################################yo😎###########

Expand Down
11 changes: 11 additions & 0 deletions api/lua/pinnacle/grpc/defs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ local pinnacle_input_v0alpha1_SetLibinputSettingRequest_TapButtonMap = {
---@field tap_drag_lock boolean?
---@field tap boolean?

---@class SetXcursorRequest
---@field theme string?
---@field size integer?

-- Process

---@class pinnacle.process.v0alpha1.SpawnRequest
Expand Down Expand Up @@ -770,6 +774,13 @@ defs.pinnacle = {
request = "pinnacle.input.v0alpha1.SetLibinputSettingRequest",
response = "google.protobuf.Empty",
},
---@type GrpcRequestArgs
SetXcursor = {
service = "pinnacle.input.v0alpha1.InputService",
method = "SetXcursor",
request = "pinnacle.input.v0alpha1.SetXcursorRequest",
response = "google.protobuf.Empty",
},
},
},
},
Expand Down
24 changes: 24 additions & 0 deletions api/lua/pinnacle/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,28 @@ function input.set_libinput_settings(settings)
end
end

---Sets the current xcursor theme.
---
---Pinnacle reads `$XCURSOR_THEME` on startup to set the theme.
---This allows you to set it at runtime.
---
---@param theme string
function input.set_xcursor_theme(theme)
client.unary_request(input_service.SetXcursor, {
theme = theme,
})
end

---Sets the current xcursor size.
---
---Pinnacle reads `$XCURSOR_SIZE` on startup to set the cursor size.
---This allows you to set it at runtime.
---
---@param size integer
function input.set_xcursor_size(size)
client.unary_request(input_service.SetXcursor, {
size = size,
})
end

return input
7 changes: 7 additions & 0 deletions api/protocol/pinnacle/input/v0alpha1/input.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ message SetLibinputSettingRequest {
}
}

message SetXcursorRequest {
optional string theme = 1;
optional uint32 size = 2;
}

service InputService {
rpc SetKeybind(SetKeybindRequest) returns (stream SetKeybindResponse);
rpc SetMousebind(SetMousebindRequest) returns (stream SetMousebindResponse);
Expand All @@ -153,4 +158,6 @@ service InputService {
rpc SetRepeatRate(SetRepeatRateRequest) returns (google.protobuf.Empty);

rpc SetLibinputSetting(SetLibinputSettingRequest) returns (google.protobuf.Empty);

rpc SetXcursor(SetXcursorRequest) returns (google.protobuf.Empty);
}
42 changes: 41 additions & 1 deletion api/rust/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use pinnacle_api_defs::pinnacle::input::{
input_service_client::InputServiceClient,
set_libinput_setting_request::{CalibrationMatrix, Setting},
KeybindDescriptionsRequest, SetKeybindRequest, SetLibinputSettingRequest,
SetMousebindRequest, SetRepeatRateRequest, SetXkbConfigRequest,
SetMousebindRequest, SetRepeatRateRequest, SetXcursorRequest, SetXkbConfigRequest,
},
};
use tokio::sync::mpsc::UnboundedSender;
Expand Down Expand Up @@ -402,6 +402,46 @@ impl Input {
}))
.unwrap();
}

/// Set the xcursor theme.
///
/// Pinnacle reads `$XCURSOR_THEME` on startup to determine the theme.
/// This allows you to set it at runtime.
///
/// # Examples
///
/// ```
/// input.set_xcursor_theme("Adwaita");
/// ```
pub fn set_xcursor_theme(&self, theme: impl ToString) {
let mut client = self.create_input_client();

block_on_tokio(client.set_xcursor(SetXcursorRequest {
theme: Some(theme.to_string()),
size: None,
}))
.unwrap();
}

/// Set the xcursor size.
///
/// Pinnacle reads `$XCURSOR_SIZE` on startup to determine the cursor size.
/// This allows you to set it at runtime.
///
/// # Examples
///
/// ```
/// input.set_xcursor_size(64);
/// ```
pub fn set_xcursor_size(&self, size: u32) {
let mut client = self.create_input_client();

block_on_tokio(client.set_xcursor(SetXcursorRequest {
theme: None,
size: Some(size),
}))
.unwrap();
}
}

/// A trait that designates anything that can be converted into a [`Keysym`].
Expand Down
27 changes: 26 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pinnacle_api_defs::pinnacle::{
set_mousebind_request::MouseEdge,
KeybindDescription, KeybindDescriptionsRequest, KeybindDescriptionsResponse, Modifier,
SetKeybindRequest, SetKeybindResponse, SetLibinputSettingRequest, SetMousebindRequest,
SetMousebindResponse, SetRepeatRateRequest, SetXkbConfigRequest,
SetMousebindResponse, SetRepeatRateRequest, SetXcursorRequest, SetXkbConfigRequest,
},
output::{
self,
Expand Down Expand Up @@ -586,6 +586,31 @@ impl input_service_server::InputService for InputService {
})
.await
}

async fn set_xcursor(
&self,
request: Request<SetXcursorRequest>,
) -> Result<Response<()>, Status> {
let request = request.into_inner();

let theme = request.theme;
let size = request.size;

run_unary_no_response(&self.sender, move |state| {
if let Some(theme) = theme {
state.pinnacle.cursor_state.set_theme(&theme);
}

if let Some(size) = size {
state.pinnacle.cursor_state.set_size(size);
}

if let Some(output) = state.pinnacle.focused_output().cloned() {
state.schedule_render(&output)
}
})
.await
}
}

pub struct ProcessService {
Expand Down
9 changes: 8 additions & 1 deletion src/api/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ impl window_service_server::WindowService for WindowService {
return;
};
let Some(window) = pointer_focus.window_for(state) else {
tracing::info!("Move grabs are currently not implemented for non-windows");
return;
};
let Some(wl_surf) = window.wl_surface() else {
Expand All @@ -498,6 +497,10 @@ impl window_service_server::WindowService for WindowService {
let seat = state.pinnacle.seat.clone();

state.move_request_server(&wl_surf, &seat, SERIAL_COUNTER.next_serial(), button);

if let Some(output) = state.pinnacle.focused_output().cloned() {
state.schedule_render(&output);
}
})
.await
}
Expand Down Expand Up @@ -579,6 +582,10 @@ impl window_service_server::WindowService for WindowService {
edges.into(),
button,
);

if let Some(output) = state.pinnacle.focused_output().cloned() {
state.schedule_render(&output);
}
})
.await
}
Expand Down
Loading
Loading