Compare commits
3 Commits
29e0f1e2dc
...
195aeb5166
| Author | SHA1 | Date | |
|---|---|---|---|
|
195aeb5166
|
|||
|
af80181897
|
|||
|
42bddf5ac7
|
@@ -5,6 +5,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <zdwm/action.h>
|
||||||
#include <zdwm/bar.h>
|
#include <zdwm/bar.h>
|
||||||
#include <zdwm/types.h>
|
#include <zdwm/types.h>
|
||||||
|
|
||||||
@@ -226,6 +227,10 @@ static void bar_output_layout(bar_output_t *bar_output, text_context_t *ctx) {
|
|||||||
}
|
}
|
||||||
item->region.end = start;
|
item->region.end = start;
|
||||||
}
|
}
|
||||||
|
if (left->count) {
|
||||||
|
left->region.start = left->items[0].region.start;
|
||||||
|
left->region.end = left->items[left->count - 1].region.end;
|
||||||
|
}
|
||||||
|
|
||||||
auto right = &bar_output->right;
|
auto right = &bar_output->right;
|
||||||
for (size_t i = right->count; i > 0; --i) {
|
for (size_t i = right->count; i > 0; --i) {
|
||||||
@@ -250,6 +255,10 @@ static void bar_output_layout(bar_output_t *bar_output, text_context_t *ctx) {
|
|||||||
}
|
}
|
||||||
item->region.start = end;
|
item->region.start = end;
|
||||||
}
|
}
|
||||||
|
if (right->count) {
|
||||||
|
right->region.start = right->items[0].region.start;
|
||||||
|
right->region.end = right->items[right->count - 1].region.end;
|
||||||
|
}
|
||||||
|
|
||||||
auto center = &bar_output->center;
|
auto center = &bar_output->center;
|
||||||
if (center->count == 0) return;
|
if (center->count == 0) return;
|
||||||
@@ -394,3 +403,49 @@ bool bar_draw(bar_t *bar) {
|
|||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
bar_item_click(zdwm_bar_item_t *item, int32_t x, zdwm_action_t *action) {
|
||||||
|
if (!(item->region.start <= x && item->region.end >= x)) return false;
|
||||||
|
|
||||||
|
if (!item->api.on_click) return true;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < item->count; ++i) {
|
||||||
|
auto cell = &item->cells[i];
|
||||||
|
if (cell->region.start <= x && cell->region.end >= x) {
|
||||||
|
*action = item->api.on_click(item, i, x, item->state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
bar_side_click(bar_side_t *side, int32_t x, zdwm_action_t *action) {
|
||||||
|
if (side->region.start > x || side->region.end < x) return false;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < side->count; ++i) {
|
||||||
|
if (bar_item_click(&side->items[i], x, action)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bar_click(
|
||||||
|
bar_t *bar,
|
||||||
|
zdwm_window_id_t window,
|
||||||
|
int32_t x,
|
||||||
|
zdwm_action_t *action
|
||||||
|
) {
|
||||||
|
for (size_t i = 0; i < bar->count; ++i) {
|
||||||
|
auto bar_output = &bar->bars[i];
|
||||||
|
if (bar_output->window_id != window) continue;
|
||||||
|
|
||||||
|
if (bar_side_click(&bar_output->left, x, action)) return true;
|
||||||
|
if (bar_item_click(&bar_output->center, x, action)) return true;
|
||||||
|
if (bar_side_click(&bar_output->right, x, action)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <zdwm/action.h>
|
||||||
#include <zdwm/bar.h>
|
#include <zdwm/bar.h>
|
||||||
#include <zdwm/types.h>
|
#include <zdwm/types.h>
|
||||||
|
|
||||||
@@ -42,3 +43,9 @@ void bar_init(bar_t *bar, listeners_t *listeners);
|
|||||||
void bar_cleanup(bar_t *bar);
|
void bar_cleanup(bar_t *bar);
|
||||||
void bar_update(bar_t *bar);
|
void bar_update(bar_t *bar);
|
||||||
bool bar_draw(bar_t *bar);
|
bool bar_draw(bar_t *bar);
|
||||||
|
bool bar_click(
|
||||||
|
bar_t *bar,
|
||||||
|
zdwm_window_id_t window,
|
||||||
|
int32_t x,
|
||||||
|
zdwm_action_t *action
|
||||||
|
);
|
||||||
|
|||||||
@@ -149,9 +149,15 @@ static zdwm_action_t bar_workspace_on_click(
|
|||||||
int32_t x,
|
int32_t x,
|
||||||
void *state
|
void *state
|
||||||
) {
|
) {
|
||||||
auto data = (bar_workspace_state_t *)state;
|
auto data = (bar_workspace_state_t *)state;
|
||||||
auto workspace = &data->workspaces[cell_index];
|
if (cell_index == data->count) {
|
||||||
|
return (zdwm_action_t){
|
||||||
|
.type = ZDWM_ACTION_LAYOUT_CYCLE,
|
||||||
|
.as.layout_cycle = {.delta = 1},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto workspace = &data->workspaces[cell_index];
|
||||||
if (workspace->info.id == data->workspace_id) {
|
if (workspace->info.id == data->workspace_id) {
|
||||||
return (zdwm_action_t){.type = ZDWM_ACTION_NONE};
|
return (zdwm_action_t){.type = ZDWM_ACTION_NONE};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ static void toggle_bar_visibility(
|
|||||||
command_buffer_push(command_buffer, &set_bar_visibility_command);
|
command_buffer_push(command_buffer, &set_bar_visibility_command);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void policy_resolve_action(
|
void policy_resolve_action(
|
||||||
const policy_context_t *ctx,
|
const policy_context_t *ctx,
|
||||||
const zdwm_action_t *action,
|
const zdwm_action_t *action,
|
||||||
command_buffer_t *out
|
command_buffer_t *out
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ typedef struct policy_context_t {
|
|||||||
const policy_bar_t bar;
|
const policy_bar_t bar;
|
||||||
} policy_context_t;
|
} policy_context_t;
|
||||||
|
|
||||||
|
void policy_resolve_action(
|
||||||
|
const policy_context_t *ctx,
|
||||||
|
const zdwm_action_t *action,
|
||||||
|
command_buffer_t *out
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 事件路由:将运行时事件翻译为语义命令
|
* @brief 事件路由:将运行时事件翻译为语义命令
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <zdwm/action.h>
|
||||||
#include <zdwm/layout.h>
|
#include <zdwm/layout.h>
|
||||||
|
|
||||||
#include "bar/bar.h"
|
#include "bar/bar.h"
|
||||||
@@ -456,10 +457,30 @@ static void runtime_scan(runtime_t *runtime) {
|
|||||||
listeners_notify_initial_windows(&runtime->listeners, &runtime->state);
|
listeners_notify_initial_windows(&runtime->listeners, &runtime->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool runtime_handle_bar_click(
|
||||||
|
const policy_context_t *ctx,
|
||||||
|
const event_t *event,
|
||||||
|
bar_t *bar,
|
||||||
|
command_buffer_t *command_buffer
|
||||||
|
) {
|
||||||
|
if (event->type != ZDWM_EVENT_POINTER_BUTTON_PRESS) return false;
|
||||||
|
|
||||||
|
auto data = &event->as.pointer_button_press;
|
||||||
|
|
||||||
|
zdwm_action_t action = {.type = ZDWM_ACTION_NONE};
|
||||||
|
if (bar_click(bar, data->window, data->local.x, &action)) {
|
||||||
|
policy_resolve_action(ctx, &action, command_buffer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void runtime_handle_event(runtime_t *runtime, short int revents) {
|
static void runtime_handle_event(runtime_t *runtime, short int revents) {
|
||||||
auto backend = runtime->backend;
|
auto backend = runtime->backend;
|
||||||
auto command_buffer = &runtime->command_buffer;
|
auto command_buffer = &runtime->command_buffer;
|
||||||
auto plan = &runtime->plan;
|
auto plan = &runtime->plan;
|
||||||
|
auto bar = &runtime->bar;
|
||||||
auto ctx = policy_context_init(runtime);
|
auto ctx = policy_context_init(runtime);
|
||||||
|
|
||||||
if (revents & POLLHUP) {
|
if (revents & POLLHUP) {
|
||||||
@@ -473,7 +494,10 @@ static void runtime_handle_event(runtime_t *runtime, short int revents) {
|
|||||||
command_buffer_reset(command_buffer);
|
command_buffer_reset(command_buffer);
|
||||||
plan_reset(plan);
|
plan_reset(plan);
|
||||||
|
|
||||||
policy_route_event(&ctx, &event, command_buffer);
|
if (!runtime_handle_bar_click(&ctx, &event, bar, command_buffer)) {
|
||||||
|
policy_route_event(&ctx, &event, command_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
policy_apply_command(&ctx, command_buffer, plan);
|
policy_apply_command(&ctx, command_buffer, plan);
|
||||||
if (plan->need_relayout) runtime_arrange(runtime);
|
if (plan->need_relayout) runtime_arrange(runtime);
|
||||||
if (plan->count) backend_apply_effect(backend, plan->effects, plan->count);
|
if (plan->count) backend_apply_effect(backend, plan->effects, plan->count);
|
||||||
|
|||||||
Reference in New Issue
Block a user