mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
pointer.c: refactor device configuration
This commit is contained in:
parent
c5a2014a2f
commit
0cdd7fac02
3 changed files with 33 additions and 15 deletions
|
@ -266,3 +266,15 @@ struct output_config *example_config_get_output(struct example_config *config,
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct device_config *example_config_get_device(struct example_config *config,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct device_config *d_config;
|
||||||
|
wl_list_for_each(d_config, &config->devices, link) {
|
||||||
|
if (strcmp(d_config->name, device->name) == 0) {
|
||||||
|
return d_config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#define _POSIX_C_SOURCE 200112L
|
#define _POSIX_C_SOURCE 200112L
|
||||||
#endif
|
#endif
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
|
#include <wlr/types/wlr_input_device.h>
|
||||||
|
|
||||||
struct output_config {
|
struct output_config {
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -41,4 +42,11 @@ void example_config_destroy(struct example_config *config);
|
||||||
struct output_config *example_config_get_output(struct example_config *config,
|
struct output_config *example_config_get_output(struct example_config *config,
|
||||||
struct wlr_output *output);
|
struct wlr_output *output);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration for the device. If the device is not configured, returns
|
||||||
|
* NULL.
|
||||||
|
*/
|
||||||
|
struct device_config *example_config_get_device(struct example_config *config,
|
||||||
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -97,31 +97,29 @@ static void handle_output_frame(struct output_state *output,
|
||||||
|
|
||||||
static void configure_devices(struct sample_state *sample) {
|
static void configure_devices(struct sample_state *sample) {
|
||||||
struct sample_input_device *dev;
|
struct sample_input_device *dev;
|
||||||
struct device_config *dc;
|
struct device_config *d_config;
|
||||||
|
|
||||||
// reset device mappings
|
// reset device mappings
|
||||||
wl_list_for_each(dev, &sample->devices, link) {
|
wl_list_for_each(dev, &sample->devices, link) {
|
||||||
wlr_cursor_map_input_to_output(sample->cursor, dev->device, NULL);
|
wlr_cursor_map_input_to_output(sample->cursor, dev->device, NULL);
|
||||||
wl_list_for_each(dc, &sample->config->devices, link) {
|
d_config = example_config_get_device(sample->config, dev->device);
|
||||||
if (strcmp(dev->device->name, dc->name) == 0) {
|
if (d_config) {
|
||||||
wlr_cursor_map_input_to_region(sample->cursor, dev->device,
|
wlr_cursor_map_input_to_region(sample->cursor, dev->device,
|
||||||
dc->mapped_box);
|
d_config->mapped_box);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct output_state *ostate;
|
struct output_state *ostate;
|
||||||
wl_list_for_each(ostate, &sample->compositor->outputs, link) {
|
wl_list_for_each(ostate, &sample->compositor->outputs, link) {
|
||||||
wl_list_for_each(dc, &sample->config->devices, link) {
|
struct wlr_output *output = ostate->output;
|
||||||
|
wl_list_for_each(dev, &sample->devices, link) {
|
||||||
// configure device to output mappings
|
// configure device to output mappings
|
||||||
if (dc->mapped_output &&
|
d_config = example_config_get_device(sample->config, dev->device);
|
||||||
strcmp(dc->mapped_output, ostate->output->name) == 0) {
|
if (d_config &&
|
||||||
wl_list_for_each(dev, &sample->devices, link) {
|
d_config->mapped_output &&
|
||||||
if (strcmp(dev->device->name, dc->name) == 0) {
|
strcmp(d_config->mapped_output, output->name) == 0) {
|
||||||
wlr_cursor_map_input_to_output(sample->cursor,
|
wlr_cursor_map_input_to_output(sample->cursor, dev->device,
|
||||||
dev->device, ostate->output);
|
ostate->output);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue