mirror of
https://github.com/swaywm/sway.git
synced 2026-04-23 06:46:27 -04:00
Base implement
This commit is contained in:
parent
5845c6e3c0
commit
f897995759
7 changed files with 47 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/types/wlr_box.h>
|
#include <wlr/types/wlr_box.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
|
#include <wlr/types/wlr_workspace_v1.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sway/tree/node.h"
|
#include "sway/tree/node.h"
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
|
|
@ -57,6 +58,8 @@ struct sway_output {
|
||||||
uint32_t refresh_nsec;
|
uint32_t refresh_nsec;
|
||||||
int max_render_time; // In milliseconds
|
int max_render_time; // In milliseconds
|
||||||
struct wl_event_source *repaint_timer;
|
struct wl_event_source *repaint_timer;
|
||||||
|
|
||||||
|
struct wlr_workspace_group_handle_v1 *workspace_group;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_output *output_create(struct wlr_output *wlr_output);
|
struct sway_output *output_create(struct wlr_output *wlr_output);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <wlr/types/wlr_data_device.h>
|
#include <wlr/types/wlr_data_device.h>
|
||||||
#include <wlr/types/wlr_input_method_v2.h>
|
#include <wlr/types/wlr_input_method_v2.h>
|
||||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||||
|
#include <wlr/types/wlr_workspace_v1.h>
|
||||||
#include <wlr/types/wlr_layer_shell_v1.h>
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
||||||
#include <wlr/types/wlr_output_management_v1.h>
|
#include <wlr/types/wlr_output_management_v1.h>
|
||||||
#include <wlr/types/wlr_output_power_management_v1.h>
|
#include <wlr/types/wlr_output_power_management_v1.h>
|
||||||
|
|
@ -84,6 +85,7 @@ struct sway_server {
|
||||||
struct wlr_input_method_manager_v2 *input_method;
|
struct wlr_input_method_manager_v2 *input_method;
|
||||||
struct wlr_text_input_manager_v3 *text_input;
|
struct wlr_text_input_manager_v3 *text_input;
|
||||||
struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
|
struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
|
||||||
|
struct wlr_workspace_manager_v1 *workspace_manager;
|
||||||
|
|
||||||
size_t txn_timeout_ms;
|
size_t txn_timeout_ms;
|
||||||
list_t *transactions;
|
list_t *transactions;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ struct sway_workspace {
|
||||||
bool urgent;
|
bool urgent;
|
||||||
|
|
||||||
struct sway_workspace_state current;
|
struct sway_workspace_state current;
|
||||||
|
|
||||||
|
struct wlr_workspace_handle_v1 *workspace_handle;
|
||||||
|
struct wl_listener *workspace_activate_request;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct workspace_config *workspace_find_config(const char *ws_name);
|
struct workspace_config *workspace_find_config(const char *ws_name);
|
||||||
|
|
|
||||||
|
|
@ -919,6 +919,8 @@ void handle_new_output(struct wl_listener *listener, void *data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
output->server = server;
|
output->server = server;
|
||||||
|
output->workspace_group = wlr_workspace_group_handle_v1_create(output->server->workspace_manager);
|
||||||
|
wlr_workspace_group_handle_v1_output_enter(output->workspace_group, wlr_output);
|
||||||
output->damage = wlr_output_damage_create(wlr_output);
|
output->damage = wlr_output_damage_create(wlr_output);
|
||||||
|
|
||||||
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
|
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,8 @@ bool server_init(struct sway_server *server) {
|
||||||
server->text_input = wlr_text_input_manager_v3_create(server->wl_display);
|
server->text_input = wlr_text_input_manager_v3_create(server->wl_display);
|
||||||
server->foreign_toplevel_manager =
|
server->foreign_toplevel_manager =
|
||||||
wlr_foreign_toplevel_manager_v1_create(server->wl_display);
|
wlr_foreign_toplevel_manager_v1_create(server->wl_display);
|
||||||
|
server->workspace_manager =
|
||||||
|
wlr_workspace_manager_v1_create(server->wl_display);
|
||||||
|
|
||||||
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
||||||
wlr_screencopy_manager_v1_create(server->wl_display);
|
wlr_screencopy_manager_v1_create(server->wl_display);
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,8 @@ void output_destroy(struct sway_output *output) {
|
||||||
"which is still referenced by transactions")) {
|
"which is still referenced by transactions")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
wlr_workspace_group_handle_v1_output_leave(output->workspace_group, output->wlr_output);
|
||||||
|
free(output->workspace_group);
|
||||||
list_free(output->workspaces);
|
list_free(output->workspaces);
|
||||||
list_free(output->current.workspaces);
|
list_free(output->current.workspaces);
|
||||||
wl_event_source_remove(output->repaint_timer);
|
wl_event_source_remove(output->repaint_timer);
|
||||||
|
|
@ -377,8 +379,22 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_workspace_coordinates(struct wlr_workspace_group_handle_v1 *workspace_group) {
|
||||||
|
struct wlr_workspace_handle_v1 *workspace_handle;
|
||||||
|
int i = wl_list_length(&workspace_group->workspaces);
|
||||||
|
wl_list_for_each(workspace_handle, &workspace_group->workspaces, link) {
|
||||||
|
struct wl_array coordinates;
|
||||||
|
wl_array_init(&coordinates);
|
||||||
|
*(int*)wl_array_add(&coordinates, sizeof(int)) = i;
|
||||||
|
wlr_workspace_handle_v1_set_coordinates(workspace_handle, &coordinates);
|
||||||
|
wl_array_release(&coordinates);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void output_sort_workspaces(struct sway_output *output) {
|
void output_sort_workspaces(struct sway_output *output) {
|
||||||
list_stable_sort(output->workspaces, sort_workspace_cmp_qsort);
|
list_stable_sort(output->workspaces, sort_workspace_cmp_qsort);
|
||||||
|
set_workspace_coordinates(output->workspace_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_get_box(struct sway_output *output, struct wlr_box *box) {
|
void output_get_box(struct sway_output *output, struct wlr_box *box) {
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,9 @@ struct sway_workspace *workspace_create(struct sway_output *output,
|
||||||
// If not already added, add the output to the lowest priority
|
// If not already added, add the output to the lowest priority
|
||||||
workspace_output_add_priority(ws, output);
|
workspace_output_add_priority(ws, output);
|
||||||
|
|
||||||
|
ws->workspace_handle = wlr_workspace_handle_v1_create(output->workspace_group);
|
||||||
|
wlr_workspace_handle_v1_set_name(ws->workspace_handle, ws->name);
|
||||||
|
|
||||||
output_add_workspace(output, ws);
|
output_add_workspace(output, ws);
|
||||||
output_sort_workspaces(output);
|
output_sort_workspaces(output);
|
||||||
|
|
||||||
|
|
@ -129,6 +132,9 @@ void workspace_destroy(struct sway_workspace *workspace) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wlr_workspace_handle_v1_destroy(workspace->workspace_handle);
|
||||||
|
|
||||||
|
free(workspace->workspace_handle);
|
||||||
free(workspace->name);
|
free(workspace->name);
|
||||||
free(workspace->representation);
|
free(workspace->representation);
|
||||||
list_free_items_and_destroy(workspace->output_priority);
|
list_free_items_and_destroy(workspace->output_priority);
|
||||||
|
|
@ -453,6 +459,16 @@ struct sway_workspace *workspace_prev(struct sway_workspace *current) {
|
||||||
return workspace_prev_next_impl(current, -1);
|
return workspace_prev_next_impl(current, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_active_current_and_diactivate_others(struct wlr_workspace_handle_v1 *workspace) {
|
||||||
|
wlr_workspace_handle_v1_set_active(workspace, true);
|
||||||
|
struct wlr_workspace_handle_v1 *tmp_workspace;
|
||||||
|
wl_list_for_each(tmp_workspace, &workspace->group->workspaces, link) {
|
||||||
|
if (workspace != tmp_workspace) {
|
||||||
|
wlr_workspace_handle_v1_set_active(tmp_workspace, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool workspace_switch(struct sway_workspace *workspace,
|
bool workspace_switch(struct sway_workspace *workspace,
|
||||||
bool no_auto_back_and_forth) {
|
bool no_auto_back_and_forth) {
|
||||||
struct sway_seat *seat = input_manager_current_seat();
|
struct sway_seat *seat = input_manager_current_seat();
|
||||||
|
|
@ -475,6 +491,9 @@ bool workspace_switch(struct sway_workspace *workspace,
|
||||||
|
|
||||||
sway_log(SWAY_DEBUG, "Switching to workspace %p:%s",
|
sway_log(SWAY_DEBUG, "Switching to workspace %p:%s",
|
||||||
workspace, workspace->name);
|
workspace, workspace->name);
|
||||||
|
|
||||||
|
set_active_current_and_diactivate_others(workspace->workspace_handle);
|
||||||
|
|
||||||
struct sway_node *next = seat_get_focus_inactive(seat, &workspace->node);
|
struct sway_node *next = seat_get_focus_inactive(seat, &workspace->node);
|
||||||
if (next == NULL) {
|
if (next == NULL) {
|
||||||
next = &workspace->node;
|
next = &workspace->node;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue