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

libinput has many options - let's support an important one. #6

Closed
01micko opened this issue May 4, 2022 · 12 comments
Closed

libinput has many options - let's support an important one. #6

01micko opened this issue May 4, 2022 · 12 comments

Comments

@01micko
Copy link
Contributor

01micko commented May 4, 2022

I don't know about you (you - as in anyone reading this) but the first thing I do on any laptop is enable tap-to-click.

Perhaps, without making this app too complex, this should be an option in the GUI.

Thanks for consideration, and if you don't mind @johanmalm I might take a look if you think this is a necessary option.

I'll await your response before proceeding :^)

Anyone else post your opinion either way.

Things to consider :

  • does the machine have a touchpad?
  • if so is it enabled?
  • if not, how do we hide that option, or do we just make it insensitive?

Thanks for reading.

@01micko
Copy link
Contributor Author

01micko commented May 4, 2022

Things to consider :

  • does the machine have a touchpad?
  • if so is it enabled?
  • if not, how do we hide that option, or do we just make it insensitive?

does the machine have a touchpad? >> if it has a battery then it's likely not a desktop
if so is it enabled? >> maybe the kernel knows?
if not, how do we hide that option, or do we just make it insensitive? >> probably just make that entry insensitive.

@Consolatis in IRC also mentioned that keyboard layout might be handy in *tweaks. Might be a bit more interesting (as in difficult) to add that capability. Really (IMHO), keyboard layout should be a distro thing, or at least wlroots, and all the other keyboard options, model, variant, rules.

@johanmalm
Copy link
Collaborator

I’m easy.
labwc sets tap-enabled by default 😃
Setting the keyboard layout is a good idea - but might a lot harder to do.

@01micko
Copy link
Contributor Author

01micko commented May 7, 2022

Hmm.. my rough attempt to find keyboard layouts - just need to confirm the general location of evdev.lst. Might give someone some ideas 😃

#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>

#define MAXLN  255 

FILE *fp;
char buf[MAXLN];
const char *lt =  "! layout";
const char *vt =  "! variant";
const char *evdev = "/etc/X11/xkb/rules/evdev.lst";
guint l = 8;
guint v = 9;

/**
* get the line number of the layout and the variant as to find
* all the layouts as they are between these two comments
*/

int
get_ln(const char *s, int i) {
	int ret, x;
	fp = fopen(evdev, "r");
	if (fp == NULL) {
		perror("Error opening file");
		exit (EXIT_FAILURE);
	}
	x = 1;
	while (fgets(buf, MAXLN, fp)) {
		if (g_ascii_strncasecmp(buf, s, i) != 0) {
			x += 1;
			continue;
		}
		ret = x;
	}
	fclose(fp);
	return ret;
}

/**
 * iterate through all the layouts
*/

void
get_layouts(void) {
	int n = 0;                 /* line count */
	int y = get_ln(lt, l) + 1; /* line no of "! layout" */
	int z = get_ln(vt, v) -2 ; /* line no of "! variant" */
	int w = y + z;
	fp = fopen(evdev, "r");
	if (fp == NULL) {
		perror("Error opening file");
		exit (EXIT_FAILURE);
	}
	while (fgets(buf, MAXLN, fp)) {
		n += 1;
		if (n < y) {
			
			continue;
		}
		if (n > z) {
			
			break;
		}
		if ((n >= y) && (n <= w)) {
			g_printf("%s", buf);
		}
	}
	fclose(fp);
}

int
main(void) {
	get_layouts();
	return 0;
}

edit: remove new line

@johanmalm
Copy link
Collaborator

Good find. On my machine it's at /usr/share/X11/xkb/rules/evdev.lst

@Consolatis
Copy link
Member

Good find. On my machine it's at /usr/share/X11/xkb/rules/evdev.lst

same for me (Debian).

@01micko
Copy link
Contributor Author

01micko commented May 19, 2022

Yeah I think slack puts it in the legacy location, and symlinks /usr/share/X11/xkb so I think we could safely assume that evdev.lst can be found at /usr/share/X11/xkb/rules/evdev.lst. A simple test for that to catch errors would be simple.

@m4lin
Copy link

m4lin commented Jun 16, 2022

hello

can confirm also Void Linux evdev.lst is in /usr/share/X11/xkb/rules

thanks @01micko for pointing me here.

@01micko
Copy link
Contributor Author

01micko commented Jul 21, 2022

Just getting back to adding keyboard layout, we should probably support 2 layouts as an option

  • a combobox with the layouts
    gtk_widget_set_sensitive (main_layout, TRUE)
  • beside that a second combobox with the layouts, with sensitive set to FALSE
    gtk_widget_set_sensitive (second_layout, FALSE)
  • a checkbox with the blurb "Check for second layout", and when checked sets the second combobox sensitive to TRUE and when that is set to TRUE the variable XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle is set

I plan to work on this soon.

@Consolatis
Copy link
Member

Consolatis commented Jul 21, 2022

That would limit the possible layouts to 2. It would also waste screen-space when there is only a single layout required (this is not that much of an issue though).

Could we instead add a button like Add layout (or a + sign) which creates a new combobox with all the layouts (+ a Remove this layout / - button)? And if multiple layouts are set, we could automatically add the toggle env var.

@01micko
Copy link
Contributor Author

01micko commented Jul 22, 2022

That would limit the possible layouts to 2. It would also waste screen-space when there is only a single layout required (this is not that much of an issue though).

Could we instead add a button like Add layout (or a + sign) which creates a new combobox with all the layouts (+ a Remove this layout / - button)? And if multiple layouts are set, we could automatically add the toggle env var.

Sure, shouldn't be much different.

@johanmalm
Copy link
Collaborator

@01micko

Simplified version (at least I think it's simpler 😄)

#define _POSIX_C_SOURCE 200809L
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>

void
print_layouts(const char *filename)
{
	bool in_layout_section = false;
	char *line = NULL;
	size_t len = 0;
	FILE *fp = fopen(filename, "r");

	if (!fp) {
		perror("Error opening file");
		exit (EXIT_FAILURE);
	}
	while (getline(&line, &len, fp) != -1) {
		char *p = strrchr(line, '\n');
		if (p) {
			*p = '\0';
		}
		if (line[0] == '\0') {
			continue;
		} else if (line[0] == '!') {
			in_layout_section = g_ascii_strncasecmp(line, "! layout", len) == 0;
		} else if (in_layout_section) {
			printf("%s\n", line);
		}
	}
	free(line);
	fclose(fp);
}

int
main(void)
{
	print_layouts("/usr/share/X11/xkb/rules/evdev.lst");
	return 0;
}

@01micko
Copy link
Contributor Author

01micko commented Aug 19, 2022

It works ;-)

@01micko 01micko closed this as completed Jan 4, 2024
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

No branches or pull requests

4 participants