From 2dbdc93ac192634856686549382fcc06e7532510 Mon Sep 17 00:00:00 2001 From: milarin Date: Wed, 14 Feb 2024 16:48:50 +0100 Subject: [PATCH] removed useless contexts --- get_bar_config.go | 8 ++----- get_binding_modes.go | 6 +---- get_config.go | 6 +---- get_current_binding_mode.go | 6 +---- get_inputs.go | 5 ++++ get_marks.go | 6 +---- get_outputs.go | 6 +---- get_tree.go | 6 +---- get_version.go | 6 +---- get_workspaces.go | 6 +---- run_command.go | 4 +--- send_tick.go | 6 +---- types.go | 48 +++++++++++++++++++++++++++++++++++++ 13 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 get_inputs.go diff --git a/get_bar_config.go b/get_bar_config.go index 0656443..c96ed78 100644 --- a/get_bar_config.go +++ b/get_bar_config.go @@ -1,13 +1,9 @@ package sway -import ( - "context" -) - -func (c *Client) GetBarIDs(ctx context.Context) ([]string, error) { +func (c *Client) GetBarIDs() ([]string, error) { return sendMessage[[]string](c, 6, "") } -func (c *Client) GetBarConfig(ctx context.Context, barID string) (*BarConfig, error) { +func (c *Client) GetBarConfig(barID string) (*BarConfig, error) { return sendMessage[*BarConfig](c, 6, barID) } diff --git a/get_binding_modes.go b/get_binding_modes.go index 4ec7da9..4acb3d1 100644 --- a/get_binding_modes.go +++ b/get_binding_modes.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetBindingModes(ctx context.Context) ([]string, error) { +func (c *Client) GetBindingModes() ([]string, error) { return sendMessage[[]string](c, 8, "") } diff --git a/get_config.go b/get_config.go index 2ed135e..522fe8d 100644 --- a/get_config.go +++ b/get_config.go @@ -1,10 +1,6 @@ package sway -import ( - "context" -) - -func (c *Client) GetConfig(ctx context.Context) (string, error) { +func (c *Client) GetConfig() (string, error) { cfg, err := sendMessage[config](c, 9, "") if err != nil { return "", err diff --git a/get_current_binding_mode.go b/get_current_binding_mode.go index 8ffeb6f..8d0bdc5 100644 --- a/get_current_binding_mode.go +++ b/get_current_binding_mode.go @@ -1,10 +1,6 @@ package sway -import ( - "context" -) - -func (c *Client) GetCurrentBindingMode(ctx context.Context) (string, error) { +func (c *Client) GetCurrentBindingMode() (string, error) { mode, err := sendMessage[name](c, 12, "") if err != nil { return "", err diff --git a/get_inputs.go b/get_inputs.go new file mode 100644 index 0000000..1b35523 --- /dev/null +++ b/get_inputs.go @@ -0,0 +1,5 @@ +package sway + +func (c *Client) GetInputs() ([]InputDevice, error) { + return sendMessage[[]InputDevice](c, 100, "") +} diff --git a/get_marks.go b/get_marks.go index 53812b7..428d431 100644 --- a/get_marks.go +++ b/get_marks.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetMarks(ctx context.Context) ([]string, error) { +func (c *Client) GetMarks() ([]string, error) { return sendMessage[[]string](c, 5, "") } diff --git a/get_outputs.go b/get_outputs.go index f592ce3..232a369 100644 --- a/get_outputs.go +++ b/get_outputs.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetOutputs(ctx context.Context) ([]Output, error) { +func (c *Client) GetOutputs() ([]Output, error) { return sendMessage[[]Output](c, 3, "") } diff --git a/get_tree.go b/get_tree.go index f0dbf10..01c591d 100644 --- a/get_tree.go +++ b/get_tree.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetTree(ctx context.Context) (*Node, error) { +func (c *Client) GetTree() (*Node, error) { return sendMessage[*Node](c, 4, "") } diff --git a/get_version.go b/get_version.go index 038af34..13bf766 100644 --- a/get_version.go +++ b/get_version.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetVersion(ctx context.Context) (*Version, error) { +func (c *Client) GetVersion() (*Version, error) { return sendMessage[*Version](c, 7, "") } diff --git a/get_workspaces.go b/get_workspaces.go index 3a74ac0..57ecebc 100644 --- a/get_workspaces.go +++ b/get_workspaces.go @@ -1,9 +1,5 @@ package sway -import ( - "context" -) - -func (c *Client) GetWorkspaces(ctx context.Context) ([]Workspace, error) { +func (c *Client) GetWorkspaces() ([]Workspace, error) { return sendMessage[[]Workspace](c, 1, "") } diff --git a/run_command.go b/run_command.go index 2e79f1d..b9bba79 100644 --- a/run_command.go +++ b/run_command.go @@ -1,12 +1,10 @@ package sway import ( - "context" - "git.milar.in/milarin/slices" ) -func (c *Client) RunCommand(ctx context.Context, cmd string) ([]error, error) { +func (c *Client) RunCommand(cmd string) ([]error, error) { results, err := sendMessage[[]commandResult](c, 0, cmd) if err != nil { return nil, err diff --git a/send_tick.go b/send_tick.go index 0b4fd5d..6259375 100644 --- a/send_tick.go +++ b/send_tick.go @@ -1,10 +1,6 @@ package sway -import ( - "context" -) - -func (c *Client) SendTick(ctx context.Context, payload string) error { +func (c *Client) SendTick(payload string) error { result, err := sendMessage[commandResult](c, 10, payload) if err != nil { return err diff --git a/types.go b/types.go index 0268679..0c40c47 100644 --- a/types.go +++ b/types.go @@ -255,6 +255,17 @@ const ( BarPositionBottom BarPosition = "bottom" ) +type InputDeviceType = string + +const ( + InputDeviceTypeKeyboard InputDeviceType = "keyboard" + InputDeviceTypePointer InputDeviceType = "pointer" + InputDeviceTypeTouch InputDeviceType = "touch" + InputDeviceTypeTabletTool InputDeviceType = "tablet_tool" + InputDeviceTypeTabletPad InputDeviceType = "tablet_pad" + InputDeviceTypeSwitch InputDeviceType = "switch" +) + type commandResult struct { Success bool `json:"success"` ParseError bool `json:"parse_error"` @@ -331,3 +342,40 @@ type config struct { type name struct { Name string `json:"name"` } + +type InputDevice struct { + Identifier string `json:"identifier"` + Name string `json:"name"` + Vendor int `json:"vendor"` + Product int `json:"product"` + Type InputDeviceType `json:"type"` + XKBActiveLayoutName string `json:"xkb_active_layout_name"` + XKBLayoutNames []string `json:"xkb_layout_names"` + XKBActiveLayoutIndex int `json:"xkb_active_layout_index"` + ScrollFactor float64 `json:"scroll_factor"` + LibInput LibInput `json:"libinput"` +} + +func (id InputDevice) String() string { + data, _ := json.MarshalIndent(id, "", "\t") + return string(data) +} + +type LibInput struct { + SendEvents string `json:"send_events"` + Tap string `json:"tap"` + TapButtonMap string `json:"tap_button_map"` + TapDrag string `json:"tap_drag"` + TapDragLock string `json:"tap_drag_lock"` + AccelSpeed float64 `json:"accel_speed"` + AccelProfile string `json:"accel_profile"` + NaturalScroll string `json:"natural_scroll"` + LeftHanded string `json:"left_handed"` + ClickMethod string `json:"click_method"` + MiddleEmulation string `json:"middle_emulation"` + ScrollMethod string `json:"scroll_method"` + ScrollButton int `json:"scroll_button"` + Dwt string `json:"dwt"` + Dwtp string `json:"dwtp"` + CalibrationMatrix [6]float64 `json:"calibration_matrix"` +}