Skip to content

feat: use keyboard selection#116

Closed
dadav wants to merge 5 commits intoemersion:masterfrom
dadav:feat/show_labels_on_selection_screen
Closed

feat: use keyboard selection#116
dadav wants to merge 5 commits intoemersion:masterfrom
dadav:feat/show_labels_on_selection_screen

Conversation

@dadav
Copy link

@dadav dadav commented Oct 8, 2022

I wanted to make a selection via keyboard and added this functionality. I also added some more options like:

  • making the font color changeable (-L): The font-color used for writing the labels and dimensions.
  • making label-selection font color changeable (-S): The font-color which is used when an area is selected.
  • split the screen in rows/cols. (-m): Splits the outputs or the given restricted areas in rows/columns.
  • show labels in rectangles (-l): Shows the label. The user can press a key and it will select the first match.
  • set font size (-g): You can change the font size with this.
  • add crosshair (-x): Used code from Crosshairs #95
  • set crosshair color (-X): You can set the crosshair color with this.

This is an example how we could make use of this:

#!/bin/bash

# uses slurp to get x y and then clicks it

div=7

while [[ $div -gt 1 ]]; do
        if [[ -z $x ]]; then
                read -r x y w h < <(slurp -l -f "%x %y %w %h" -m "$div:$div")
        else
                read -r x y w h < <(<<<"$x,$y ${w}x${h}" slurp -l -f "%x %y %w %h" -m "$div:$div")
        fi

        div=$((div-2))
done

swaymsg seat - cursor set "$x" "$y"
swaymsg seat - cursor press button1
swaymsg seat - cursor release button1

And this is how I make use of this (first select the x, y coords and then use swaymsg to click it...like..what if someday the mouse is broken?)

foo.mp4

@tmccombs tmccombs self-assigned this Sep 5, 2025
Copy link
Contributor

@tmccombs tmccombs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, but this PR also makes a lot of changes. Could it be split up into smaller pull requests so the changes could be reviewed in isolation?

switch (key_state) {
case WL_KEYBOARD_KEY_STATE_PRESSED:
switch (keysym) {
case XKB_KEY_Return:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would conflict with #138

int key_size;
key_size = xkb_state_key_get_utf8(seat->xkb_state, key + 8, NULL, 0) + 1;
if (key_size) {
pressed_key = (char *) malloc(key_size * sizeof(char));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid allocating every time a key is pressed?

Couldn't we just use a char[1], since the only keyboard selectors we allow are single ascii characters, and should thus fit in a single byte? If the result doesn't fit in a single byte, then it isn't a key we care about.

#define FONT_SIZE 14
#define FONT_COLOR 0xFFFFFFFF
#define CHOICE_FONT_COLOR 0xFCBA03FF
#define KEYBOAD_SELECTORS "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define KEYBOAD_SELECTORS "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define KEYBOARD_SELECTORS "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"

?

@dadav dadav closed this Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants