Skip to content
Open
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
24 changes: 24 additions & 0 deletions docs/docs/configuration/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,37 @@ override). Each value is an `InputDeviceConfig` with optional `keyboard`,
| `model` | `string` | Keyboard model |
| `repeatRate` | `number` | Key repeats per second |
| `repeatDelay` | `number` | Delay (ms) before key repeat starts |
| `numLock` | `"on" \| "off" \| "restore"` | Num Lock state at session start (see below) |

```ts
input.global = {
keyboard: {layout: 'us', options: 'caps:ctrl_modifier', repeatRate: 60, repeatDelay: 250},
};
```

### Num Lock at session start

`numLock` sets the Num Lock state once per session, when the compositor first
applies a config with it. Later config reloads and new keyboards do not change
it, so a toggle you make with the key stays. A keymap change (a reload, or
another `layout`) keeps the current state.

- `"on"` / `"off"`: start with Num Lock on or off.
- `"restore"`: start with the state the previous session ended with. The
compositor saves each change to `$XDG_STATE_HOME/shoji_wm/num-lock`
(`~/.local/state/shoji_wm/num-lock` when `XDG_STATE_HOME` is unset). If the
file does not exist yet, Num Lock stays as it is.

Without `numLock`, the compositor does not touch Num Lock. Only
`input.global.keyboard.numLock` is read: all keyboards share one Num Lock
state, so a per-device value has no effect.

```ts
input.global = {
keyboard: {numLock: 'restore'},
};
```

## Reading the active keyboard layout

Subscribe to the seat's actual XKB layout from TypeScript:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,37 @@ COMPOSITOR.input.configure((input, context) => {
| `model` | `string` | キーボードモデル |
| `repeatRate` | `number` | 1秒あたりのキーリピート回数 |
| `repeatDelay` | `number` | キーリピート開始までの遅延(ミリ秒) |
| `numLock` | `"on" \| "off" \| "restore"` | セッション開始時の Num Lock の状態(下記参照) |

```ts
input.global = {
keyboard: {layout: 'us', options: 'caps:ctrl_modifier', repeatRate: 60, repeatDelay: 250},
};
```

### セッション開始時の Num Lock

`numLock` は、コンポジターがこの設定を含む config を最初に適用したときに、セッションごとに
1回だけ Num Lock の状態を設定します。その後の config の再読み込みやキーボードの追加では
変更しないため、キーで切り替えた状態はそのまま残ります。キーマップの変更(再読み込みや
別の `layout`)でも現在の状態は保たれます。

- `"on"`/`"off"`: Num Lock をオン/オフで開始します。
- `"restore"`: 前回のセッション終了時の状態で開始します。コンポジターは変更のたびに
`$XDG_STATE_HOME/shoji_wm/num-lock`(`XDG_STATE_HOME` が未設定なら
`~/.local/state/shoji_wm/num-lock`)に保存します。ファイルがまだ無い場合、Num Lock は
そのままです。

`numLock` を指定しない場合、コンポジターは Num Lock に触れません。読み取るのは
`input.global.keyboard.numLock` だけです。すべてのキーボードが1つの Num Lock の状態を
共有するため、デバイスごとの値は効果がありません。

```ts
input.global = {
keyboard: {numLock: 'restore'},
};
```

## ノートパソコンの蓋

`COMPOSITOR.event.onLidSwitch` は蓋の開閉を通知します。蓋を閉じている間だけ
Expand Down
2 changes: 2 additions & 0 deletions packages/shoji_wm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import type {
InputScrollMethod,
InputTapButtonMap,
KeyboardInputConfig,
KeyboardNumLock,
PointerInputConfig,
TouchpadInputConfig,
ProcessController,
Expand Down Expand Up @@ -839,6 +840,7 @@ export type {
InputScrollMethod,
InputTapButtonMap,
KeyboardInputConfig,
KeyboardNumLock,
PointerInputConfig,
TouchpadInputConfig,
CursorConfig,
Expand Down
16 changes: 16 additions & 0 deletions packages/shoji_wm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,7 @@ export type InputMotionSpace = "logical" | "physical";
export type InputClickMethod = "buttonAreas" | "clickfinger";
export type InputScrollMethod = "none" | "twoFinger" | "edge" | "onButtonDown";
export type InputTapButtonMap = "leftRightMiddle" | "leftMiddleRight";
export type KeyboardNumLock = "on" | "off" | "restore";

export interface KeyboardInputConfig {
repeatRate?: number;
Expand All @@ -2379,6 +2380,21 @@ export interface KeyboardInputConfig {
layout?: string;
variant?: string;
options?: string;
/**
* Num Lock state at session start. Set once per session, when a config
* with it is first applied: later reloads and new keyboards do not undo a
* toggle made with the key. `"restore"` starts with the state the previous
* session ended with, saved in `$XDG_STATE_HOME/shoji_wm/num-lock`.
* Read from `input.global` only: all keyboards share one Num Lock state.
* Unset: the compositor does not touch Num Lock.
* セッション開始時の Num Lock の状態です。この設定を含む config を最初に適用したときに
* セッションごとに1回だけ設定し、その後の再読み込みやキーボードの追加ではキーで切り替えた
* 状態を戻しません。`"restore"` は前回のセッション終了時の状態
* (`$XDG_STATE_HOME/shoji_wm/num-lock` に保存)で開始します。
* すべてのキーボードが1つの Num Lock の状態を共有するため、`input.global` の値だけを
* 読み取ります。未指定の場合、コンポジターは Num Lock に触れません。
*/
numLock?: KeyboardNumLock;
}

export interface PointerInputConfig {
Expand Down
1 change: 1 addition & 0 deletions src/shojiwm_lib/src/keyboard_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl ShojiWM {
caps_lock: modifiers.caps_lock,
num_lock: modifiers.num_lock,
};
self.num_lock_observed(locks.num_lock);
let layout = keyboard.with_xkb_state(self, |context| {
let xkb = context.xkb().lock().unwrap();
let layout = xkb.active_layout();
Expand Down
1 change: 1 addition & 0 deletions src/shojiwm_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub mod keyboard_layout;
pub mod lid_switch;
pub mod log_rate_limit;
pub mod modifier_tap;
pub mod num_lock;
pub mod output_power;
pub mod plasma_virtual_desktop;
pub mod plasma_window_management;
Expand Down
Loading