Compare commits
10 Commits
ee82bc6975
...
a5dbf902cf
| Author | SHA1 | Date |
|---|---|---|
|
|
a5dbf902cf | |
|
|
895bd53e8c | |
|
|
fe5c722969 | |
|
|
b75d7cb4e2 | |
|
|
2568d3cc23 | |
|
|
67cafa3de1 | |
|
|
4ae6e8d5b1 | |
|
|
3a6c255b97 | |
|
|
cfaa4348e8 | |
|
|
7e5da8e27b |
|
|
@ -1,6 +1,5 @@
|
|||
#include "bar.h"
|
||||
#include "cairo.h"
|
||||
#include "config.def.h"
|
||||
#include "config.h"
|
||||
#include "input.h"
|
||||
#include "main.h"
|
||||
|
|
@ -27,6 +26,7 @@ static void bar_status_render(struct Pipeline *pipeline, struct Bar *bar, cairo_
|
|||
static int bar_width(struct Pipeline *pipeline, void *data, unsigned int future_widths);
|
||||
|
||||
const struct PipelineListener bar_pipeline_listener = { .render = bar_render, .width = bar_width, };
|
||||
const struct HotspotListener bar_hotspot_listener = { .click = bar_click, .bounds = bar_bounds };
|
||||
|
||||
void bar_click(struct Monitor *monitor, void *data, uint32_t button, double x, double y) {
|
||||
if (!monitor || !data)
|
||||
|
|
@ -155,8 +155,7 @@ struct Bar *bar_create(struct List *hotspots, struct Pipeline *pipeline) {
|
|||
|
||||
pipeline_add(pipeline, &bar_pipeline_listener, bar);
|
||||
struct Hotspot *hotspot = list_add(hotspots, ecalloc(1, sizeof(*hotspot)));
|
||||
hotspot->click = bar_click;
|
||||
hotspot->bounds = bar_bounds;
|
||||
hotspot->listener = &bar_hotspot_listener;
|
||||
hotspot->data = bar;
|
||||
|
||||
bar->x = 0;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ static const int *schemes[3][2] = {
|
|||
|
||||
/*
|
||||
* Tags
|
||||
* Must not exceed 31 tags and amount must match dwl's tagcount.
|
||||
*/
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
|
|
|
|||
19
src/input.c
19
src/input.c
|
|
@ -15,6 +15,7 @@
|
|||
#include <wayland-util.h>
|
||||
|
||||
static int button_cmp(const void *left, const void *right);
|
||||
static void hotspots_process(struct Monitor* monitor, double x, double y, uint32_t button);
|
||||
static void pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value);
|
||||
static void pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete);
|
||||
static void pointer_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source);
|
||||
|
|
@ -158,7 +159,7 @@ void pointer_frame(void *data, struct wl_pointer *wl_pointer) {
|
|||
if (!monitor) return;
|
||||
|
||||
for (int i = 0; i < pointer->buttons->length; i++)
|
||||
process_hotspots(pointer->focused_monitor, pointer->x, pointer->y,
|
||||
hotspots_process(pointer->focused_monitor, pointer->x, pointer->y,
|
||||
*(uint32_t*)pointer->buttons->data[i]);
|
||||
list_elements_destroy(pointer->buttons, free);
|
||||
pointer->buttons = list_create(0);
|
||||
|
|
@ -173,14 +174,16 @@ void pointer_process_scroll(struct Pointer *pointer, unsigned int axis_index) {
|
|||
struct Axis *axis = &pointer->axis[axis_index];
|
||||
if (axis->discrete_steps) {
|
||||
for (int i = 0; i < axis->discrete_steps; i++)
|
||||
process_hotspots(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, axis->value));
|
||||
hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, axis->value));
|
||||
axis->value = 0;
|
||||
axis->discrete_steps = 0;
|
||||
} else {
|
||||
while (abs(axis->value) > SCROLL_THRESHOLD) {
|
||||
if (axis->value > 0){
|
||||
process_hotspots(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, SCROLL_THRESHOLD));
|
||||
hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, SCROLL_THRESHOLD));
|
||||
axis->value -= SCROLL_THRESHOLD;
|
||||
} else {
|
||||
process_hotspots(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, -SCROLL_THRESHOLD));
|
||||
hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, -SCROLL_THRESHOLD));
|
||||
axis->value += SCROLL_THRESHOLD;
|
||||
}
|
||||
}
|
||||
|
|
@ -224,19 +227,19 @@ void pointer_update_cursor(struct Pointer *pointer) {
|
|||
wl_surface_commit(pointer->cursor_surface);
|
||||
}
|
||||
|
||||
void process_hotspots(struct Monitor* monitor, double x, double y, uint32_t button) {
|
||||
void hotspots_process(struct Monitor* monitor, double x, double y, uint32_t button) {
|
||||
struct Hotspot *hotspot;
|
||||
for (int i = 0; i < monitor->hotspots->length; i++) {
|
||||
hotspot = monitor->hotspots->data[i];
|
||||
|
||||
double hotspot_x = 0, hotspot_y = 0, hotspot_width = 0, hotspot_height = 0;
|
||||
hotspot->bounds(hotspot->data, &hotspot_x, &hotspot_y, &hotspot_width, &hotspot_height);
|
||||
hotspot->listener->bounds(hotspot->data, &hotspot_x, &hotspot_y, &hotspot_width, &hotspot_height);
|
||||
|
||||
if (!( x > hotspot_x && y > hotspot_y &&
|
||||
x < (hotspot_x+hotspot_width) && y < (hotspot_y+hotspot_height)))
|
||||
continue;
|
||||
|
||||
hotspot->click(monitor, hotspot->data, button, x, y);
|
||||
hotspot->listener->click(monitor, hotspot->data, button, x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -389,7 +392,7 @@ void touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t t
|
|||
if (!point) return;
|
||||
|
||||
uint32_t button = touch_point_to_button(point, time);
|
||||
process_hotspots(point->focused_monitor, point->x, point->y, button);
|
||||
hotspots_process(point->focused_monitor, point->x, point->y, button);
|
||||
}
|
||||
|
||||
uint32_t wl_axis_to_button(int axis, wl_fixed_t value) {
|
||||
|
|
|
|||
|
|
@ -51,15 +51,18 @@ struct Seat {
|
|||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct Hotspot {
|
||||
struct HotspotListener {
|
||||
void (*click)(struct Monitor *monitor, void *data, uint32_t button, double x, double y);
|
||||
void (*bounds)(void *data, double *x, double *y, double *width, double *height);
|
||||
};
|
||||
|
||||
struct Hotspot {
|
||||
const struct HotspotListener *listener;
|
||||
void *data;
|
||||
};
|
||||
|
||||
extern const struct wl_seat_listener seat_listener;
|
||||
|
||||
void process_hotspots(struct Monitor* monitor, double x, double y, uint32_t button);
|
||||
void seat_destroy(struct Seat *seat);
|
||||
|
||||
#endif // INPUT_H_
|
||||
|
|
|
|||
30
src/main.c
30
src/main.c
|
|
@ -35,6 +35,7 @@ static void fifo_setup(void);
|
|||
static void monitor_destroy(struct Monitor *monitor);
|
||||
static struct Monitor *monitor_from_name(const char *name);
|
||||
struct Monitor *monitor_from_surface(const struct wl_surface *surface);
|
||||
static void monitor_initialize(struct Monitor *monitor);
|
||||
static void monitor_update(struct Monitor *monitor);
|
||||
static void pipe_in(int fd, short mask, void *data);
|
||||
static void registry_global_add(void *data, struct wl_registry *registry, uint32_t name,
|
||||
|
|
@ -195,9 +196,9 @@ void monitor_destroy(struct Monitor *monitor) {
|
|||
if (!monitor)
|
||||
return;
|
||||
|
||||
wl_list_remove(&monitor->link);
|
||||
free(monitor->xdg_name);
|
||||
wl_output_release(monitor->wl_output);
|
||||
if (wl_output_get_version(monitor->wl_output) >= WL_OUTPUT_RELEASE_SINCE_VERSION)
|
||||
wl_output_release(monitor->wl_output);
|
||||
list_elements_destroy(monitor->hotspots, free);
|
||||
pipeline_destroy(monitor->pipeline);
|
||||
bar_destroy(monitor->bar);
|
||||
|
|
@ -224,6 +225,17 @@ struct Monitor *monitor_from_surface(const struct wl_surface *surface) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void monitor_initialize(struct Monitor *monitor) {
|
||||
if (!monitor) return;
|
||||
|
||||
monitor->hotspots = list_create(1);
|
||||
monitor->pipeline = pipeline_create();
|
||||
monitor->bar = bar_create(monitor->hotspots, monitor->pipeline);
|
||||
if (!monitor->pipeline || !monitor->bar)
|
||||
panic("Failed to create a pipline or bar for monitor: %s", monitor->xdg_name);
|
||||
monitor_update(monitor);
|
||||
}
|
||||
|
||||
void monitor_update(struct Monitor *monitor) {
|
||||
if (!monitor)
|
||||
return;
|
||||
|
|
@ -257,12 +269,6 @@ void registry_global_add(void *data, struct wl_registry *registry, uint32_t name
|
|||
monitor->wl_name = name;
|
||||
monitor->xdg_name = NULL;
|
||||
monitor->xdg_output = NULL;
|
||||
monitor->hotspots = list_create(1);
|
||||
monitor->pipeline = pipeline_create();
|
||||
monitor->bar = bar_create(monitor->hotspots, monitor->pipeline);
|
||||
|
||||
if (!monitor->pipeline || !monitor->bar)
|
||||
return;
|
||||
|
||||
wl_list_insert(&monitors, &monitor->link);
|
||||
|
||||
|
|
@ -271,6 +277,9 @@ void registry_global_add(void *data, struct wl_registry *registry, uint32_t name
|
|||
|
||||
monitor->xdg_output = zxdg_output_manager_v1_get_xdg_output(output_manager, monitor->wl_output);
|
||||
zxdg_output_v1_add_listener(monitor->xdg_output, &xdg_output_listener, monitor);
|
||||
|
||||
if (!running) return;
|
||||
monitor_initialize(monitor);
|
||||
}
|
||||
else if (STRING_EQUAL(interface, wl_seat_interface.name)) {
|
||||
struct Seat *seat = ecalloc(1, sizeof(*seat));
|
||||
|
|
@ -378,6 +387,11 @@ void setup(void) {
|
|||
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
struct Monitor *monitor;
|
||||
wl_list_for_each(monitor, &monitors, link) {
|
||||
monitor_initialize(monitor);
|
||||
}
|
||||
|
||||
if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) < 0)
|
||||
panic("STDIN_FILENO O_NONBLOCK");
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ void pipeline_destroy(struct Pipeline *pipeline) {
|
|||
|
||||
list_elements_destroy(pipeline->callbacks, free);
|
||||
g_object_unref(pipeline->context);
|
||||
g_object_unref(pipeline->font->description);
|
||||
pango_font_description_free(pipeline->font->description);
|
||||
free(pipeline->font);
|
||||
shm_destroy(pipeline->shm);
|
||||
wl_surface_destroy(pipeline->surface);
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ static struct Buffer buffer_create(struct MemoryMapping *map, struct wl_shm_pool
|
|||
|
||||
void buffer_destroy(struct Buffer *buffer) {
|
||||
if (!buffer) return;
|
||||
|
||||
wl_buffer_destroy(buffer->buffer);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
struct MemoryMapping memory_mapping_create(int fd, int pool_size) {
|
||||
|
|
@ -67,9 +65,7 @@ struct MemoryMapping memory_mapping_create(int fd, int pool_size) {
|
|||
|
||||
void memory_mapping_destroy(struct MemoryMapping *map) {
|
||||
if (!map) return;
|
||||
|
||||
munmap(map->ptr, map->size);
|
||||
free(map);
|
||||
}
|
||||
|
||||
struct Shm *shm_create(int width, int height, enum wl_shm_format format) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ void list_resize(struct List *list) {
|
|||
return;
|
||||
|
||||
list->allocated *= 2;
|
||||
list->data = realloc(list->data, list->allocated);
|
||||
list->data = realloc(list->data, sizeof(void*) * list->allocated);
|
||||
}
|
||||
|
||||
char *string_create(const char *fmt, ...) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <wayland-util.h>
|
||||
|
||||
#define STRING_EQUAL(string1, string2) strcmp(string1, string2) == 0
|
||||
#define STRINGN_EQUAL(string1, string2, n) strcmp(string1, string2, n) == 0
|
||||
#define STRINGN_EQUAL(string1, string2, n) strncmp(string1, string2, n) == 0
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0] )
|
||||
|
||||
struct List {
|
||||
|
|
|
|||
Loading…
Reference in New Issue