wl_seat

wl_seat (ver 9)
struct wl_seat_listener *listenerハンドラ構造体
wl_seat_add_listenerハンドラ設定
wl_seat_destroy破棄
wl_seat_release解放
wl_seat_get_pointerwl_pointer を作成
wl_seat_get_keyboardwl_keyboard を作成
wl_seat_get_touchwl_touch を作成
wl_pointer
struct wl_pointer_listenerハンドラ構造体
wl_pointer_add_listenerハンドラ設定
wl_pointer_destroy破棄
wl_pointer_release解放
wl_pointer_set_cursorポインタのカーソル形状をセット
wl_keyboard
struct wl_keyboard_listenerハンドラ構造体
wl_keyboard_add_listenerハンドラ設定
wl_keyboard_destroy破棄
wl_keyboard_release解放
wl_seat (ver 9)
struct wl_seat_listener *listener {
    void (*capabilities)(void *data, struct wl_seat *wl_seat, uint32_t capabilities);
    //ver 2
    void (*name)(void *data, struct wl_seat *wl_seat, const char *name);
};
ハンドラ構造体
capabilities
ポインタ、キーボード、タッチのデバイスが、使用可能か使用不可になった時に送られる。

capabilities:
WL_SEAT_CAPABILITY_POINTER = 1
WL_SEAT_CAPABILITY_KEYBOARD = 2
WL_SEAT_CAPABILITY_TOUCH = 4

フラグが ON の場合、wl_seat_get_pointer() などを使って、各オブジェクトを取得できる。
フラグが OFF になった場合、wl_pointer_destroy() や wl_pointer_release() を使って、オブジェクトを破棄する必要がある。

※一部のコンポジタでは、クライアントが ver 4 以下を使用している場合、オブジェクトが使用不可になった後も、ポインタなどのイベントを再び送信することがあるが、この動作は信用してはならない。
name
ver 2
複数の seat がある場合のために、それらを識別するための名前 (UTF-8) が通知される。

名前に規則はなく、wl_seat ごとに名前が異なる。
すべてのクライアントに対して、同じ名前が使用され、名前はプロセス間で共有される。

name イベントは、バインド直後に送信される。
このイベントは wl_seat オブジェクトごとに1回だけ送信され、wl_seat グローバルの存続期間中変更されない。

wl_seat グローバルが破棄されて、後で再作成された場合、コンポジターは同じ名前を再使用できる。
int wl_seat_add_listener(struct wl_seat *wl_seat, const struct wl_seat_listener *listener, void *data);
ハンドラ設定
void wl_seat_destroy(struct wl_seat *wl_seat);
破棄する。
void wl_seat_release(struct wl_seat *wl_seat);
//ver 5
サーバーに、このオブジェクトは今後使用しないことを通知する。
struct wl_pointer *wl_seat_get_pointer(struct wl_seat *wl_seat);
wl_pointer を作成
struct wl_keyboard *wl_seat_get_keyboard(struct wl_seat *wl_seat);
wl_keyboard を作成
struct wl_touch *wl_seat_get_touch(struct wl_seat *wl_seat);
wl_touch を作成
wl_pointer
struct wl_pointer_listener {
    void (*enter)(void *data, struct wl_pointer *wl_pointer,
        uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
    void (*leave)(void *data, struct wl_pointer *wl_pointer,
        uint32_t serial, struct wl_surface *surface);
    void (*motion)(void *data, struct wl_pointer *wl_pointer,
        uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y);
    void (*button)(void *data, struct wl_pointer *wl_pointer,
        uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
    void (*axis)(void *data, struct wl_pointer *wl_pointer,
        uint32_t time, uint32_t axis, wl_fixed_t value);
    //ver 5
    void (*frame)(void *data, struct wl_pointer *wl_pointer);
    void (*axis_source)(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source);
    void (*axis_stop)(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis);
    void (*axis_discrete)(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete);
    //ver 8
    void (*axis_value120)(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t value120);
    //ver 9
    void (*axis_relative_direction)(void *data, struct wl_pointer *wl_pointer, uint32_t axis, uint32_t direction);
};
wl_fixed_t は、int32_t 型、24:8 の固定少数点数。
time は、ミリ秒単位のタイムスタンプで、開始位置は未定義。
enter
ポインタがサーフェス内に入った。
カーソル形状の変更はクライアント側で処理する。
leave
ポインタがサーフェスから出た。
motion
ポインタがサーフェス内で移動した。
button
マウスボタンが押された/離された。
位置は、最後の enter/motion の値を使う。

button は、Linux カーネルの linux/input-event-codes.h ヘッダーに定義されているボタンコード (BTN_LEFT など)。
16 bit までの値は、将来のカーネルのイベントコードリストへの追加用に予約されている。
0xFFFF を超えるコードは現在未定義だが、このプロトコルの将来のバージョンで使用される可能性がある。

state:
WL_POINTER_BUTTON_STATE_RELEASED = 0
WL_POINTER_BUTTON_STATE_PRESSED = 1
axis
ホイールなどのスクロール時。
斜めなどの場合は、複数のイベントが来る。

axis: 移動した軸
WL_POINTER_AXIS_VERTICAL_SCROLL = 0
WL_POINTER_AXIS_HORIZONTAL_SCROLL = 1

value は移動の方向と量。サーバーにより量は異なる。
frame
var 5
一連のイベントを一つのかたまりとして、それらが終了した時に送られる。

axis/motion/leave など、すべてのイベントが対象。
enter/leave は一つにまとめないことが望ましい。
axis_source
var 5
frame イベント前にオプションとして送信され、フレーム内のイベントのソース情報を提供する。
ソースが不明な場合は、送信されない。

axis_source
WL_POINTER_AXIS_SOURCE_WHEEL = 0  //ホイール回転
WL_POINTER_AXIS_SOURCE_FINGER = 1 //指のタッチ
WL_POINTER_AXIS_SOURCE_CONTINUOUS = 2 //連続
# ver 6
WL_POINTER_AXIS_SOURCE_WHEEL_TILT = 3 //ホイールの傾き

axis_source は、イベントが、物理的にどうやって生成されたか。
CONTINUOUS は、ボタンが押されている間スクロールするといった場合。
WHEEL_TILT は、横方向の傾きによって生成される。

FINGER の場合、ユーザーが指をデバイスから離したときに axis_stop イベントが送信される。
それ以外の場合、axis_stop イベントは、送信される場合と送信されない場合がある。
コンポジタが axis_stop イベントを送信するかどうかは、ハードウェア固有で、実装に依存する。

axis_discrete と axis_source の順序は保証されていない。
axis_stop
var 5
スクロールおよびその他の軸の停止が通知される。
このイベント後に、同じ axis_source を持つ axis イベントが来た場合、新しい軸の開始と見なす必要がある。

time は、axis イベントのタイムスタンプと同じように解釈される。
タイムスタンプ値は、先行する axis イベントと同じにすることができる。
axis_discrete
var 5
スクロールおよびその他の軸のステップ情報が送られる。
このイベントは単独では発生せず、axis イベントと同時に来る。

このイベントはオプションである。
タッチパッド上での2本指のスクロールのような連続スクロールデバイスは、ステップを持たないため、このイベントを生成しない。

discrete はステップ値。
-1 なら、負の方向に一段階移動という意味。

axis_discrete と axis_source の順序は保証されていない。
axis_value120
ver 8
ホイールスクロールの高解像度の情報。

このイベントは、wl_pointer の ver 8 以降をサポートするクライアントにおいて、axis_discrete イベントの代わりになる。
同じ frame で、axis_source イベントが発生する場合、このイベントにその axis_source が適用される。

value120 は、120 を1単位としたステップ値。0 であってはならない。
30 の場合は、120 の 1/4 なので、正方向の1ステップの 1/4 量。
-240 の場合は、負方向の x 2 となる。

axis_value120 と axis_source の順序は保証されない。
axis_relative_direction
ver 9
wl_pointer.axis イベントの場合、このイベントは、wl_pointer.axis イベントを引き起こすエンティティの移動方向を指定する。

例:
- タッチパッドでユーザーの指が下に移動し、wl_pointer.axis vertical_scroll down イベントが発生する場合、物理的な方向は「同一」。
- タッチパッドでユーザーの指が下に移動し、wl_pointer.axis vertical_scroll up scroll up イベント (「自然なスクロール」) が発生する場合、物理的な方向は「反転」。

クライアントは、この情報を使用して、コンポーネントのスクロールモーションを調整できる。
具体的には、自然なスクロールを有効にすると、従来のスクロールと比較して、コンテンツの方向が変わる。
ボリューム コントロール スライダーなどの一部のウィジェットは、自然なスクロールがアクティブかどうかに関係なく、通常は物理的な方向に一致する必要がる。
このイベントにより、クライアントは、ウィジェットのスクロール方向を、物理的な方向に一致させることができる。

このイベントは単独では発生せず、この axis 値を表す wl_pointer.axis イベントと連動する。
プロトコルは、各 axis_relative_direction イベントの後に、同じ wl_pointer.frame 内で、同じ axis 番号を持つ 1 つの axis イベントが必ず続くことを保証する。
プロトコルでは、axis_relative_direction と連動 axis イベントの間に、他のイベントが発生することを許可していることに注意すること。

axis 番号は、関連付けられた axis イベントの番号と同じ。

axis_relative_direction、axis_discrete、axis_source の順序は保証されない。
int wl_pointer_add_listener(struct wl_pointer *wl_pointer,
    const struct wl_pointer_listener *listener, void *data);
ハンドラ設定
void wl_pointer_destroy(struct wl_pointer *wl_pointer);
破棄
void wl_pointer_release(struct wl_pointer *wl_pointer);
//ver 3
サーバーに、このオブジェクトは今後使用しないことを通知する。

このリクエストによってオブジェクトは破棄されるため、この後に wl_pointer_destroy() を使用しないこと。
void wl_pointer_set_cursor(struct wl_pointer *wl_pointer,
    uint32_t serial, struct wl_surface *surface, int32_t hotspot_x, int32_t hotspot_y);
wl_surface を、ポインタのカーソルイメージとしてセットする。

この要求はサーフェスにカーソルの役割を与える。
サーフェスにすでに別の役割がある場合は、プロトコルエラーが発生する。

surface が NULL の場合、カーソル形状は非表示になる。
hotspot_x, hotspot_y は、ホットスポット位置。
serial
enter イベント時のシリアル値
wl_keyboard
struct wl_keyboard_listener {
    void (*keymap)(void *data, struct wl_keyboard *wl_keyboard,
        uint32_t format, int32_t fd, uint32_t size);
    void (*enter)(void *data, struct wl_keyboard *wl_keyboard,
        uint32_t serial, struct wl_surface *surface, struct wl_array *keys);
    void (*leave)(void *data, struct wl_keyboard *wl_keyboard,
        uint32_t serial, struct wl_surface *surface);
    void (*key)(void *data, struct wl_keyboard *wl_keyboard,
        uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
    void (*modifiers)(void *data, struct wl_keyboard *wl_keyboard,
        uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
        uint32_t mods_locked, uint32_t group);
    //ver 4
    void (*repeat_info)(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay);
};
ハンドラ構造体
keymap
キーマップを設定する必要がある時に来る。

format
WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP = 0
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 = 1

fd, size はキーマップの設定情報が入った共有メモリの fd とデータサイズ。
mmap() でメモリマップして文字列データとして扱う。
enter
キーボードフォーカスが来た時。
ウィンドウがアクティブになって、キー入力ができる状態になった時。

keys: 現在倫理的に押されているキー。
leave
キーボードフォーカスが離れた時
key
キーが押された/離された時。

key は、Linux udev のキー番号。linux/input-event-codes.h で定義されている値。

state
WL_KEYBOARD_KEY_STATE_RELEASED = 0
WL_KEYBOARD_KEY_STATE_PRESSED = 1
modifiers
装飾キーやロックの状態が変更した時。
値はキーマップによって異なる。

mods_depressed : 押されている装飾のフラグ
mods_latched : ラッチされた装飾
mods_locked : ロックされている装飾
group : キーボードレイアウト
repeat_info
ver 4
キーリピートの間隔と、キーリピートを開始するまでの時間 (ms) を提供する。

wl_keyboard オブジェクトが作成されるとすぐに送信され、設定が変更されると再び送信される。

delay は最初にキーを押した時からキーリピートを開始するまでの時間。
rate はリピート開始後にキーを出力する間隔。0 でキーリピート無効。
int wl_keyboard_add_listener(struct wl_keyboard *wl_keyboard,
    const struct wl_keyboard_listener *listener, void *data);
ハンドラ設定
void wl_keyboard_destroy(struct wl_keyboard *wl_keyboard);
破棄
void wl_keyboard_release(struct wl_keyboard *wl_keyboard);
//ver 3
サーバーに、このオブジェクトは今後使用しないことを通知する。