ver: upgrade to wlroots-0.19 version

This commit is contained in:
DreamMaoMao
2025-04-13 09:05:09 +08:00
parent 54de782f90
commit d636ef97ac
12 changed files with 2179 additions and 1947 deletions

351
IM.h
View File

@@ -1,7 +1,11 @@
#ifdef IM #ifdef IM
#include <assert.h> #include <assert.h>
#include <wlr/types/wlr_input_method_v2.h>
#include <wlr/types/wlr_text_input_v3.h> #include <wlr/types/wlr_text_input_v3.h>
#include <wlr/types/wlr_input_method_v2.h>
#ifdef HANDWRITE
#include <handwrite-unstable-v1-protocol.h>
#endif
/** /**
* The relay structure manages the relationship between text-input and * The relay structure manages the relationship between text-input and
@@ -53,6 +57,7 @@ struct dwl_text_input {
struct wl_listener text_input_destroy; struct wl_listener text_input_destroy;
}; };
struct dwl_input_popup { struct dwl_input_popup {
struct dwl_input_method_relay *relay; struct dwl_input_method_relay *relay;
struct wlr_input_popup_surface_v2 *popup_surface; struct wlr_input_popup_surface_v2 *popup_surface;
@@ -65,6 +70,7 @@ struct dwl_input_popup {
int x, y; int x, y;
bool visible; bool visible;
struct wl_listener popup_map; struct wl_listener popup_map;
struct wl_listener popup_unmap; struct wl_listener popup_unmap;
struct wl_listener popup_destroy; struct wl_listener popup_destroy;
@@ -72,6 +78,7 @@ struct dwl_input_popup {
//struct wl_listener focused_surface_unmap; //struct wl_listener focused_surface_unmap;
}; };
void dwl_input_method_relay_init(struct dwl_input_method_relay *relay); void dwl_input_method_relay_init(struct dwl_input_method_relay *relay);
// Updates currently focused surface. Surface must belong to the same // Updates currently focused surface. Surface must belong to the same
// seat. // seat.
@@ -82,74 +89,90 @@ static void handle_im_grab_keyboard(struct wl_listener *listener, void *data);
static void handle_im_keyboard_grab_destroy(struct wl_listener *listener, static void handle_im_keyboard_grab_destroy(struct wl_listener *listener,
void *data); void *data);
static void input_popup_update(struct dwl_input_popup *popup); static void input_popup_update(struct dwl_input_popup *popup);
static struct dwl_text_input *relay_get_focused_text_input(struct dwl_input_method_relay *relay);
struct wlr_input_method_manager_v2 *input_method_manager; struct wlr_input_method_manager_v2 *input_method_manager;
struct wlr_text_input_manager_v3 *text_input_manager; struct wlr_text_input_manager_v3 *text_input_manager;
struct dwl_input_method_relay *input_relay; struct dwl_input_method_relay *input_relay;
// static int NO_printstatus=0; // i suspect that printstatus will make dwl hang with fcitx5
#ifdef HANDWRITE
static void receive_handwrite_text_from_handwrite_input_app(struct wl_client *client, struct wl_resource *resource, const char *text){
struct dwl_text_input *text_input;
wlr_log(WLR_INFO,"receive_handwrite_text_from_handwrite_input_app called with:%s",text);
text_input = relay_get_focused_text_input(input_relay);
if (text_input){
wlr_log(WLR_INFO,"receive_handwrite_text_from_handwrite_input_app will commit %s",text);
wlr_text_input_v3_send_commit_string(text_input->input,text);
wlr_text_input_v3_send_done(text_input->input);
}else wlr_log(WLR_INFO, "no focused text_input for handwrite");
}
const struct zwp_handwrite_v1_interface handwrite_interface_impl = {
.send_handwrite_text = receive_handwrite_text_from_handwrite_input_app,
};
// struct wl_client* handwrite_app=NULL;//TODO: multiple handwrite app instance?
// void zwp_handwrite_v1_handle_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id){
// wlr_log(WLR_INFO,"zwp_handwrite_v1_handle_bind called");
// handwrite_app = client;
// struct wl_resource *resource = wl_resource_create(client, &zwp_handwrite_v1_interface, zwp_handwrite_v1_interface.version, id);
// wl_resource_set_implementation(resource, &handwrite_interface_impl, NULL, NULL);
// }
#endif
/** /**
* Get keyboard grab of the seat from sway_keyboard if we should forward events * Get keyboard grab of the seat from sway_keyboard if we should forward events
* to it. * to it.
* *
* Returns NULL if the keyboard is not grabbed by an input method, * Returns NULL if the keyboard is not grabbed by an input method,
* or if event is from virtual keyboard of the same client as grab. * or if event is from virtual keyboard
* TODO: see https://github.com/swaywm/wlroots/issues/2322
*/ */
static struct wlr_input_method_keyboard_grab_v2 * static struct wlr_input_method_keyboard_grab_v2 *keyboard_get_im_grab(KeyboardGroup* kb) {
keyboard_get_im_grab(Keyboard *kb) {
struct wlr_input_method_v2 *input_method = input_relay->input_method; struct wlr_input_method_v2 *input_method = input_relay->input_method;
struct wlr_virtual_keyboard_v1 *virtual_keyboard =
wlr_input_device_get_virtual_keyboard(&kb->wlr_keyboard->base);
if (!input_method || !input_method->keyboard_grab ||
(virtual_keyboard &&
wl_resource_get_client(virtual_keyboard->resource) ==
wl_resource_get_client(input_method->keyboard_grab->resource))) {
if (!input_method){ if (!input_method){
wlr_log(WLR_DEBUG, wlr_log(WLR_DEBUG, "keypress keyboard_get_im_grab return NULL:no input_method");
"keypress keyboard_get_im_grab return NULL:no input_method");
} else if (!input_method->keyboard_grab) {
wlr_log(WLR_DEBUG, "keypress keyboard_get_im_grab return NULL:no "
"input_method->keyboard_grab");
}
if (virtual_keyboard) {
wlr_log(WLR_DEBUG,
"keypress keyboard_get_im_grab return NULL:virtual_keyboard");
}
return NULL; return NULL;
} } else if (!input_method->keyboard_grab){
return input_method->keyboard_grab; wlr_log(WLR_DEBUG, "keypress keyboard_get_im_grab return NULL:no input_method->keyboard_grab");
return NULL;
} else if (kb != kb_group) {
wlr_log(WLR_DEBUG, "keypress keyboard_get_im_grab return NULL:virtual_keyboard");
return NULL;
} else return input_method->keyboard_grab;
} }
static void handle_im_grab_keyboard(struct wl_listener *listener, void *data) { static void handle_im_grab_keyboard(struct wl_listener *listener, void *data) {
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, input_method_grab_keyboard); input_method_grab_keyboard);
// wl_container_of 宏的第二个参数sample, //wl_container_of 宏的第二个参数sample, 这里是relay,无须是已经初始化的变量,只要是返回值类型的变量就可以了,这里就是dwl_input_method_relay类型的变量
// 这里是relay,无须是已经初始化的变量,只要是返回值类型的变量就可以了,这里就是dwl_input_method_relay类型的变量
struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data;
// send modifier state to grab // send modifier state to grab
struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(seat); struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(seat);
if (active_keyboard){ if (active_keyboard){
wlr_log(WLR_INFO,"im_grab_keyboard"); wlr_log(WLR_INFO,"im_grab_keyboard");
wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab,active_keyboard);
active_keyboard); wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab, &active_keyboard->modifiers);
wlr_input_method_keyboard_grab_v2_send_modifiers( }
keyboard_grab, &active_keyboard->modifiers); else
} else
wlr_log(WLR_INFO,"im_grab_keyboard but no active keyboard"); wlr_log(WLR_INFO,"im_grab_keyboard but no active keyboard");
wl_signal_add(&keyboard_grab->events.destroy, wl_signal_add(&keyboard_grab->events.destroy,
&relay->input_method_keyboard_grab_destroy); &relay->input_method_keyboard_grab_destroy);
relay->input_method_keyboard_grab_destroy.notify = relay->input_method_keyboard_grab_destroy.notify =
handle_im_keyboard_grab_destroy; handle_im_keyboard_grab_destroy;
} }
static void handle_im_keyboard_grab_destroy(struct wl_listener *listener, static void handle_im_keyboard_grab_destroy(struct wl_listener *listener, void *data) {
void *data) { struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
struct dwl_input_method_relay *relay = input_method_keyboard_grab_destroy);
wl_container_of(listener, relay, input_method_keyboard_grab_destroy);
struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data;
wlr_log(WLR_DEBUG,"im_keyboard_grab_destroy"); wlr_log(WLR_DEBUG,"im_keyboard_grab_destroy");
wl_list_remove(&relay->input_method_keyboard_grab_destroy.link); wl_list_remove(&relay->input_method_keyboard_grab_destroy.link);
@@ -160,8 +183,9 @@ static void handle_im_keyboard_grab_destroy(struct wl_listener *listener,
} }
} }
static struct dwl_text_input *
relay_get_focusable_text_input(struct dwl_input_method_relay *relay) { static struct dwl_text_input *relay_get_focusable_text_input(
struct dwl_input_method_relay *relay) {
struct dwl_text_input *text_input = NULL; struct dwl_text_input *text_input = NULL;
wl_list_for_each(text_input, &relay->text_inputs, link) { wl_list_for_each(text_input, &relay->text_inputs, link) {
if (text_input->pending_focused_surface) { if (text_input->pending_focused_surface) {
@@ -171,8 +195,8 @@ relay_get_focusable_text_input(struct dwl_input_method_relay *relay) {
return NULL; return NULL;
} }
static struct dwl_text_input * static struct dwl_text_input *relay_get_focused_text_input(
relay_get_focused_text_input(struct dwl_input_method_relay *relay) { struct dwl_input_method_relay *relay) {
struct dwl_text_input *text_input = NULL; struct dwl_text_input *text_input = NULL;
wl_list_for_each(text_input, &relay->text_inputs, link) { wl_list_for_each(text_input, &relay->text_inputs, link) {
if (text_input->input->focused_surface) { if (text_input->input->focused_surface) {
@@ -185,8 +209,8 @@ relay_get_focused_text_input(struct dwl_input_method_relay *relay) {
static void handle_im_commit(struct wl_listener *listener, void *data) { static void handle_im_commit(struct wl_listener *listener, void *data) {
struct wlr_input_method_v2 *context; struct wlr_input_method_v2 *context;
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, input_method_commit); input_method_commit);
struct dwl_text_input *text_input = relay_get_focused_text_input(relay); struct dwl_text_input *text_input = relay_get_focused_text_input(relay);
if (!text_input) { if (!text_input) {
@@ -207,18 +231,17 @@ static void handle_im_commit(struct wl_listener *listener, void *data) {
context->current.commit_text); context->current.commit_text);
wlr_log(WLR_DEBUG,"commit_text: %s", context->current.commit_text); wlr_log(WLR_DEBUG,"commit_text: %s", context->current.commit_text);
} }
if (context->current.delete.before_length || if (context->current.delete.before_length
context->current.delete.after_length) { || context->current.delete.after_length) {
wlr_text_input_v3_send_delete_surrounding_text( wlr_text_input_v3_send_delete_surrounding_text(text_input->input,
text_input->input, context->current.delete.before_length, context->current.delete.before_length,
context->current.delete.after_length); context->current.delete.after_length);
} }
wlr_text_input_v3_send_done(text_input->input); wlr_text_input_v3_send_done(text_input->input);
} }
static void static void text_input_set_pending_focused_surface(
text_input_set_pending_focused_surface(struct dwl_text_input *text_input, struct dwl_text_input *text_input, struct wlr_surface *surface) {
struct wlr_surface *surface) {
wl_list_remove(&text_input->pending_focused_surface_destroy.link); wl_list_remove(&text_input->pending_focused_surface_destroy.link);
text_input->pending_focused_surface = surface; text_input->pending_focused_surface = surface;
@@ -233,11 +256,17 @@ text_input_set_pending_focused_surface(struct dwl_text_input *text_input,
static void handle_im_destroy(struct wl_listener *listener, void *data) { static void handle_im_destroy(struct wl_listener *listener, void *data) {
struct dwl_text_input *text_input; struct dwl_text_input *text_input;
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, input_method_destroy); input_method_destroy);
struct wlr_input_method_v2 *context = data; struct wlr_input_method_v2 *context = data;
wlr_log(WLR_INFO,"IM destroy"); wlr_log(WLR_INFO,"IM destroy");
assert(context == relay->input_method); assert(context == relay->input_method);
wl_list_remove(&relay->input_method_commit.link);
wl_list_remove(&relay->input_method_grab_keyboard.link);
wl_list_remove(&relay->input_method_new_popup_surface.link);
wl_list_remove(&relay->input_method_destroy.link);
relay->input_method = NULL; relay->input_method = NULL;
text_input = relay_get_focused_text_input(relay); text_input = relay_get_focused_text_input(relay);
@@ -258,21 +287,20 @@ static void relay_send_im_state(struct dwl_input_method_relay *relay,
return; return;
} }
// TODO: only send each of those if they were modified // TODO: only send each of those if they were modified
wlr_input_method_v2_send_surrounding_text( wlr_input_method_v2_send_surrounding_text(input_method,
input_method, input->current.surrounding.text, input->current.surrounding.text, input->current.surrounding.cursor,
input->current.surrounding.cursor, input->current.surrounding.anchor); input->current.surrounding.anchor);
wlr_input_method_v2_send_text_change_cause(input_method, wlr_input_method_v2_send_text_change_cause(input_method,
input->current.text_change_cause); input->current.text_change_cause);
wlr_input_method_v2_send_content_type(input_method, wlr_input_method_v2_send_content_type(input_method,
input->current.content_type.hint, input->current.content_type.hint, input->current.content_type.purpose);
input->current.content_type.purpose);
wlr_input_method_v2_send_done(input_method); wlr_input_method_v2_send_done(input_method);
// TODO: pass intent, display popup size // TODO: pass intent, display popup size
} }
static void handle_text_input_enable(struct wl_listener *listener, void *data) { static void handle_text_input_enable(struct wl_listener *listener, void *data) {
struct dwl_text_input *text_input = struct dwl_text_input *text_input = wl_container_of(listener, text_input,
wl_container_of(listener, text_input, text_input_enable); text_input_enable);
if (text_input->relay->input_method == NULL) { if (text_input->relay->input_method == NULL) {
wlr_log(WLR_INFO, "text_input_enable but input method is NULL"); wlr_log(WLR_INFO, "text_input_enable but input method is NULL");
return; return;
@@ -289,16 +317,14 @@ static void handle_text_input_enable(struct wl_listener *listener, void *data) {
/* static void handle_text_input_commit(struct wl_listener *listener, */ /* static void handle_text_input_commit(struct wl_listener *listener, */
/* void *data) { */ /* void *data) { */
/* struct dwl_text_input *text_input = wl_container_of(listener, /* struct dwl_text_input *text_input = wl_container_of(listener, text_input, */
* text_input, */
/* text_input_commit); */ /* text_input_commit); */
/* if (!text_input->input->current_enabled) { */ /* if (!text_input->input->current_enabled) { */
/* wlr_log(WLR_INFO, "text_input_commit but not enabled"); */ /* wlr_log(WLR_INFO, "text_input_commit but not enabled"); */
/* return; */ /* return; */
/* } */ /* } */
/* if (text_input->relay->input_method == NULL) { */ /* if (text_input->relay->input_method == NULL) { */
/* wlr_log(WLR_INFO, "text_input_commit but input method is NULL"); /* wlr_log(WLR_INFO, "text_input_commit but input method is NULL"); */
*/
/* return; */ /* return; */
/* } */ /* } */
/* wlr_log(WLR_DEBUG, "text_input_commit"); */ /* wlr_log(WLR_DEBUG, "text_input_commit"); */
@@ -318,20 +344,21 @@ static void relay_disable_text_input(struct dwl_input_method_relay *relay,
wlr_input_method_v2_send_deactivate(relay->input_method); wlr_input_method_v2_send_deactivate(relay->input_method);
wlr_log(WLR_INFO,"input_method deactivate for xwayland"); wlr_log(WLR_INFO,"input_method deactivate for xwayland");
#endif #endif
// but if you keep the line above while remove the line below, input Chinese //but if you keep the line above while remove the line below, input Chinese in geogebra(xwayland) won't work
// in geogebra(xwayland) won't work
relay_send_im_state(relay, text_input->input); relay_send_im_state(relay, text_input->input);
} }
static void handle_text_input_destroy(struct wl_listener *listener, static void handle_text_input_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct dwl_text_input *text_input = struct dwl_text_input *text_input = wl_container_of(listener, text_input,
wl_container_of(listener, text_input, text_input_destroy); text_input_destroy);
if (text_input->input->current_enabled) { if (text_input->input->current_enabled) {
wlr_log(WLR_INFO,"text_input_destroy when still enabled"); wlr_log(WLR_INFO,"text_input_destroy when still enabled");
relay_disable_text_input(text_input->relay, text_input); relay_disable_text_input(text_input->relay, text_input);
} else { }
else {
wlr_log(WLR_INFO,"text_input_destroy"); wlr_log(WLR_INFO,"text_input_destroy");
} }
@@ -346,8 +373,8 @@ static void handle_text_input_destroy(struct wl_listener *listener,
static void handle_pending_focused_surface_destroy(struct wl_listener *listener, static void handle_pending_focused_surface_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct dwl_text_input *text_input = struct dwl_text_input *text_input = wl_container_of(listener, text_input,
wl_container_of(listener, text_input, pending_focused_surface_destroy); pending_focused_surface_destroy);
struct wlr_surface *surface = data; struct wlr_surface *surface = data;
assert(text_input->pending_focused_surface == surface); assert(text_input->pending_focused_surface == surface);
text_input->pending_focused_surface = NULL; text_input->pending_focused_surface = NULL;
@@ -355,10 +382,11 @@ static void handle_pending_focused_surface_destroy(struct wl_listener *listener,
wl_list_init(&text_input->pending_focused_surface_destroy.link); wl_list_init(&text_input->pending_focused_surface_destroy.link);
} }
static void relay_handle_text_input_new(struct wl_listener *listener, static void relay_handle_text_input_new(struct wl_listener *listener,
void *data) { void *data) {
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, text_input_new); text_input_new);
struct wlr_text_input_v3 *wlr_text_input = data; struct wlr_text_input_v3 *wlr_text_input = data;
if (seat != wlr_text_input->seat) { if (seat != wlr_text_input->seat) {
return; return;
@@ -393,22 +421,20 @@ static void relay_handle_text_input_new(struct wl_listener *listener,
wl_list_init(&input->pending_focused_surface_destroy.link); wl_list_init(&input->pending_focused_surface_destroy.link);
} }
static LayerSurface* layer_surface_from_wlr_layer_surface_v1( static LayerSurface* layer_surface_from_wlr_layer_surface_v1(
struct wlr_layer_surface_v1* layer_surface) { struct wlr_layer_surface_v1* layer_surface) {
return layer_surface->data; return layer_surface->data;
} }
static void get_parent_and_output_box(struct wlr_surface *focused_surface, static void get_parent_and_output_box(struct wlr_surface *focused_surface,
struct wlr_box *parent, struct wlr_box *parent, struct wlr_box *output_box) {
struct wlr_box *output_box) {
struct wlr_output *output; struct wlr_output *output;
struct wlr_box output_box_tmp; struct wlr_box output_box_tmp;
struct wlr_layer_surface_v1 *layer_surface; struct wlr_layer_surface_v1 *layer_surface;
Client *client = NULL;
LayerSurface *l = NULL;
if ((layer_surface = if ((layer_surface=wlr_layer_surface_v1_try_from_wlr_surface(focused_surface))) {
wlr_layer_surface_v1_try_from_wlr_surface(focused_surface))) {
LayerSurface* layer = LayerSurface* layer =
layer_surface_from_wlr_layer_surface_v1(layer_surface); layer_surface_from_wlr_layer_surface_v1(layer_surface);
output = layer->layer_surface->output; output = layer->layer_surface->output;
@@ -416,51 +442,39 @@ static void get_parent_and_output_box(struct wlr_surface *focused_surface,
*parent = layer->geom; *parent = layer->geom;
parent->x += output_box_tmp.x; parent->x += output_box_tmp.x;
parent->y += output_box_tmp.y; parent->y += output_box_tmp.y;
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"get_parent_and_output_box layersurface output_box_tmp->x %d y %d",output_box_tmp.x, output_box_tmp.y);
"get_parent_and_output_box layersurface output_box_tmp->x %d y %d", wlr_log(WLR_INFO,"get_parent_and_output_box layersurface parent->x %d y %d",parent->x,parent->y);
output_box_tmp.x, output_box_tmp.y);
wlr_log(WLR_INFO,
"get_parent_and_output_box layersurface parent->x %d y %d",
parent->x, parent->y);
} else { } else {
//Client *client = client_from_wlr_surface(focused_surface);
Client *client = NULL;
LayerSurface *l = NULL;
toplevel_from_wlr_surface(focused_surface, &client, &l); toplevel_from_wlr_surface(focused_surface, &client, &l);
output = wlr_output_layout_output_at(output_layout, client->geom.x, output = wlr_output_layout_output_at(output_layout,
client->geom.y); client->geom.x, client->geom.y);
wlr_output_layout_get_box(output_layout, output,&output_box_tmp); wlr_output_layout_get_box(output_layout, output,&output_box_tmp);
parent->x = client->geom.x + client->bw; parent->x = client->geom.x + client->bw;
parent->y = client->geom.y + client->bw; parent->y = client->geom.y + client->bw;
parent->width = client->geom.width; parent->width = client->geom.width;
parent->height = client->geom.height; parent->height = client->geom.height;
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"get_parent_and_output_box client output_box_tmp->x %d y %d",output_box_tmp.x, output_box_tmp.y);
"get_parent_and_output_box client output_box_tmp->x %d y %d", wlr_log(WLR_INFO,"get_parent_and_output_box client client->geom.x %d y %d",client->geom.x,client->geom.y);
output_box_tmp.x, output_box_tmp.y); wlr_log(WLR_INFO,"get_parent_and_output_box client client->bw %d",client->bw);
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"get_parent_and_output_box client parent->x %d y %d",parent->x,parent->y);
"get_parent_and_output_box client client->geom.x %d y %d",
client->geom.x, client->geom.y);
wlr_log(WLR_INFO, "get_parent_and_output_box client client->bw %d",
client->bw);
wlr_log(WLR_INFO, "get_parent_and_output_box client parent->x %d y %d",
parent->x, parent->y);
} }
//*output_box = output_box_tmp; //*output_box = output_box_tmp;
memcpy(output_box,&output_box_tmp,sizeof(struct wlr_box)); memcpy(output_box,&output_box_tmp,sizeof(struct wlr_box));
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"get_parent_and_output_box output_box x %d y %d width %d height %d",output_box->x,output_box->y,output_box->width,output_box->height);
"get_parent_and_output_box output_box x %d y %d width %d height %d",
output_box->x, output_box->y, output_box->width, output_box->height);
} }
// 如果当前focused wlr_text_input_v3.features 满足 // 如果当前focused wlr_text_input_v3.features 满足 WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE, 不含这个feature就弹出在父窗口左上角
// WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE, // 根据 wlr_text_input_v3.current.cursor_rectangle 计算出一个wlr_box
// 不含这个feature就弹出在父窗口左上角 根据 // 再调用 wlr_input_popup_surface_v2_send_text_input_rectangle 和 wlr_scene_node_set_position
// wlr_text_input_v3.current.cursor_rectangle 计算出一个wlr_box 再调用
// wlr_input_popup_surface_v2_send_text_input_rectangle 和
// wlr_scene_node_set_position
static void input_popup_update(struct dwl_input_popup *popup) { static void input_popup_update(struct dwl_input_popup *popup) {
struct wlr_surface* focused_surface; struct wlr_surface* focused_surface;
struct wlr_box output_box, parent, input_cursor; struct wlr_box output_box, parent, cursor;
int x1, x2, y1, y2, x, y, available_right, available_left, available_down, int x1, x2, y1, y2, x, y, available_right, available_left, available_down,
available_up, popup_width, popup_height; available_up, popup_width, popup_height;
bool cursor_rect, x1_in_bounds, y1_in_bounds, x2_in_bounds, y2_in_bounds; bool cursor_rect, x1_in_bounds, y1_in_bounds, x2_in_bounds, y2_in_bounds;
@@ -471,18 +485,17 @@ static void input_popup_update(struct dwl_input_popup *popup) {
return; return;
} }
// TODO: //TODO: https://gitlab.freedesktop.org/wlroots/wlroots/-/commit/743da5c0ae723098fe772aadb93810f60e700ab9
// https://gitlab.freedesktop.org/wlroots/wlroots/-/commit/743da5c0ae723098fe772aadb93810f60e700ab9
if (!popup->popup_surface->surface->mapped) { if (!popup->popup_surface->surface->mapped) {
return; return;
} }
cursor_rect = text_input->input->current.features & cursor_rect = text_input->input->current.features
WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE; & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
focused_surface = text_input->input->focused_surface; focused_surface = text_input->input->focused_surface;
input_cursor = text_input->input->current.cursor_rectangle; cursor = text_input->input->current.cursor_rectangle;
get_parent_and_output_box(focused_surface, &parent, &output_box); get_parent_and_output_box(focused_surface, &parent, &output_box);
@@ -490,92 +503,80 @@ static void input_popup_update(struct dwl_input_popup *popup) {
popup_height = popup->popup_surface->surface->current.height; popup_height = popup->popup_surface->surface->current.height;
if (!cursor_rect) { if (!cursor_rect) {
input_cursor.x = 0; cursor.x = 0;
input_cursor.y = 0; cursor.y = 0;
input_cursor.width = parent.width; cursor.width = parent.width;
input_cursor.height = parent.height; cursor.height = parent.height;
wlr_log(WLR_INFO,"input_popup_update !cursor_rect"); wlr_log(WLR_INFO,"input_popup_update !cursor_rect");
popup->x=parent.x; popup->x=parent.x;
popup->y=parent.y; popup->y=parent.y;
popup->visible=true; popup->visible=true;
} else { }
wlr_log(WLR_INFO, else {
"input_popup_update input_cursor x %d y %d width %d height %d", wlr_log(WLR_INFO,"input_popup_update cursor x %d y %d width %d height %d",cursor.x,cursor.y,cursor.width,cursor.height);
input_cursor.x, input_cursor.y, input_cursor.width,
input_cursor.height);
x1 = parent.x + input_cursor.x; x1 = parent.x + cursor.x;
x2 = parent.x + input_cursor.x + input_cursor.width; x2 = parent.x + cursor.x + cursor.width;
y1 = parent.y + input_cursor.y; y1 = parent.y + cursor.y;
y2 = parent.y + input_cursor.y + input_cursor.height; y2 = parent.y + cursor.y + cursor.height;
x = x1; x = x1;
y = y2; y = y2;
wlr_log(WLR_INFO, "input_popup_update x1 %d x2 %d y1 %d y2 %d; x %d y %d", wlr_log(WLR_INFO,"input_popup_update x1 %d x2 %d y1 %d y2 %d; x %d y %d",x1,x2,y1,y2,x,y);
x1, x2, y1, y2, x, y);
available_right = output_box.x + output_box.width - x1; available_right = output_box.x + output_box.width - x1;
available_left = x2 - output_box.x; available_left = x2 - output_box.x;
if (available_right < popup_width && available_left > available_right) { if (available_right < popup_width && available_left > available_right) {
x = x2 - popup_width; x = x2 - popup_width;
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"input_popup_update available_left %d popup_width %d available_right %d; x %d",available_left,popup_width,available_right,x);
"input_popup_update available_left %d popup_width %d "
"available_right %d; x %d",
available_left, popup_width, available_right, x);
} }
available_down = output_box.y + output_box.height - y2; available_down = output_box.y + output_box.height - y2;
available_up = y1 - output_box.y; available_up = y1 - output_box.y;
if (available_down < popup_height && available_up > available_down) { if (available_down < popup_height && available_up > available_down) {
y = y1 - popup_height; y = y1 - popup_height;
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"input_popup_update available up %d popup_height %d available_down %d; y %d",available_up,popup_height,available_down,y);
"input_popup_update available up %d popup_height %d "
"available_down %d; y %d",
available_up, popup_height, available_down, y);
} }
popup->x = x; popup->x = x;
popup->y = y; popup->y = y;
// Hide popup if input_cursor position is completely out of bounds // Hide popup if cursor position is completely out of bounds
x1_in_bounds = (input_cursor.x >= 0 && input_cursor.x < parent.width); x1_in_bounds = (cursor.x >= 0 && cursor.x < parent.width);
y1_in_bounds = (input_cursor.y >= 0 && input_cursor.y < parent.height); y1_in_bounds = (cursor.y >= 0 && cursor.y < parent.height);
x2_in_bounds = (input_cursor.x + input_cursor.width >= 0 && x2_in_bounds = (cursor.x + cursor.width >= 0
input_cursor.x + input_cursor.width < parent.width); && cursor.x + cursor.width < parent.width);
y2_in_bounds = (input_cursor.y + input_cursor.height >= 0 && y2_in_bounds = (cursor.y + cursor.height >= 0
input_cursor.y + input_cursor.height < parent.height); && cursor.y + cursor.height < parent.height);
popup->visible = popup->visible =
(x1_in_bounds && y1_in_bounds) || (x2_in_bounds && y2_in_bounds); (x1_in_bounds && y1_in_bounds) || (x2_in_bounds && y2_in_bounds);
struct wlr_box box = { struct wlr_box box = {
.x = x1 - x, .x = x1 - x,
.y = y1 - y, .y = y1 - y,
.width = input_cursor.width, .width = cursor.width,
.height = input_cursor.height, .height = cursor.height,
}; };
wlr_input_popup_surface_v2_send_text_input_rectangle(popup->popup_surface, wlr_input_popup_surface_v2_send_text_input_rectangle(
&box); popup->popup_surface, &box);
wlr_log(WLR_INFO, wlr_log(WLR_INFO,"input_popup_update send_text_input_rect box.x %d box.y %d",box.x,box.y);
"input_popup_update send_text_input_rect box.x %d box.y %d", box.x,
box.y);
} }
wlr_log(WLR_INFO, "input_popup_update x %d y %d visible %s", popup->x, wlr_log(WLR_INFO,"input_popup_update x %d y %d visible %s",popup->x,popup->y,popup->visible?"true":"false");
popup->y, popup->visible ? "true" : "false");
wlr_scene_node_set_position(&popup->scene->node, popup->x, popup->y); wlr_scene_node_set_position(&popup->scene->node, popup->x, popup->y);
} }
static void handle_im_popup_map(struct wl_listener *listener, void *data) { static void handle_im_popup_map(struct wl_listener *listener, void *data) {
struct dwl_input_popup *popup = wl_container_of(listener, popup, popup_map); struct dwl_input_popup *popup =
wl_container_of(listener, popup, popup_map);
wlr_log(WLR_INFO, "IM_popup_map"); wlr_log(WLR_INFO, "IM_popup_map");
//popup->scene = &wlr_scene_tree_create(layers[LyrIMPopup])->node; //popup->scene = &wlr_scene_tree_create(layers[LyrIMPopup])->node;
popup->scene = wlr_scene_tree_create(layers[LyrIMPopup]); popup->scene = wlr_scene_tree_create(layers[LyrIMPopup]);
popup->scene_surface = wlr_scene_subsurface_tree_create( popup->scene_surface = wlr_scene_subsurface_tree_create(popup->scene,popup->popup_surface->surface);
popup->scene, popup->popup_surface->surface); //popup->scene_surface = &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node;
// popup->scene_surface =
// &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node;
//popup->scene_surface->data = popup; //popup->scene_surface->data = popup;
popup->scene_surface->node.data = popup; popup->scene_surface->node.data = popup;
@@ -585,7 +586,8 @@ static void handle_im_popup_map(struct wl_listener *listener, void *data) {
} }
static void handle_im_popup_unmap(struct wl_listener *listener, void *data) { static void handle_im_popup_unmap(struct wl_listener *listener, void *data) {
struct dwl_input_popup *popup = wl_container_of(listener, popup, popup_unmap); struct dwl_input_popup *popup =
wl_container_of(listener, popup, popup_unmap);
//input_popup_update(popup); //input_popup_update(popup);
wlr_log(WLR_INFO,"im_popup_unmap"); wlr_log(WLR_INFO,"im_popup_unmap");
@@ -608,12 +610,12 @@ static void handle_im_popup_destroy(struct wl_listener *listener, void *data) {
relay->popup=NULL; relay->popup=NULL;
} }
static void handle_im_new_popup_surface(struct wl_listener *listener,
void *data) { static void handle_im_new_popup_surface(struct wl_listener *listener, void *data) {
// struct dwl_text_input* text_input; // struct dwl_text_input* text_input;
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, input_method_new_popup_surface); input_method_new_popup_surface);
struct dwl_input_popup *popup = calloc(1, sizeof(*popup)); struct dwl_input_popup *popup = calloc(1, sizeof(*popup));
wlr_log(WLR_INFO, "IM_new_popup_surface"); wlr_log(WLR_INFO, "IM_new_popup_surface");
@@ -623,23 +625,25 @@ static void handle_im_new_popup_surface(struct wl_listener *listener,
popup->popup_surface = data; popup->popup_surface = data;
popup->popup_surface->data = popup; popup->popup_surface->data = popup;
wl_signal_add(&popup->popup_surface->surface->events.map, &popup->popup_map); wl_signal_add(&popup->popup_surface->surface->events.map, &popup->popup_map);
popup->popup_map.notify = handle_im_popup_map; popup->popup_map.notify = handle_im_popup_map;
wl_signal_add(&popup->popup_surface->surface->events.unmap, wl_signal_add(&popup->popup_surface->surface->events.unmap, &popup->popup_unmap);
&popup->popup_unmap);
popup->popup_unmap.notify = handle_im_popup_unmap; popup->popup_unmap.notify = handle_im_popup_unmap;
wl_signal_add(&popup->popup_surface->events.destroy, &popup->popup_destroy); wl_signal_add(
&popup->popup_surface->events.destroy, &popup->popup_destroy);
popup->popup_destroy.notify = handle_im_popup_destroy; popup->popup_destroy.notify = handle_im_popup_destroy;
} }
static void relay_handle_input_method_new(struct wl_listener *listener, static void relay_handle_input_method_new(struct wl_listener *listener,
void *data) { void *data) {
struct dwl_text_input *text_input; struct dwl_text_input *text_input;
struct dwl_input_method_relay *relay = struct dwl_input_method_relay *relay = wl_container_of(listener, relay,
wl_container_of(listener, relay, input_method_new); input_method_new);
struct wlr_input_method_v2 *input_method = data; struct wlr_input_method_v2 *input_method = data;
if (seat != input_method->seat) { if (seat != input_method->seat) {
@@ -648,9 +652,7 @@ static void relay_handle_input_method_new(struct wl_listener *listener,
} }
if (relay->input_method != NULL) { if (relay->input_method != NULL) {
wlr_log( wlr_log(WLR_INFO, "input_method_new Attempted to connect second input method to a seat");
WLR_INFO,
"input_method_new Attempted to connect second input method to a seat");
wlr_input_method_v2_send_unavailable(input_method); wlr_input_method_v2_send_unavailable(input_method);
return; return;
} }
@@ -687,7 +689,8 @@ void dwl_input_method_relay_init(struct dwl_input_method_relay *relay) {
relay->popup=NULL; relay->popup=NULL;
relay->text_input_new.notify = relay_handle_text_input_new; relay->text_input_new.notify = relay_handle_text_input_new;
wl_signal_add(&text_input_manager->events.text_input, &relay->text_input_new); wl_signal_add(&text_input_manager->events.text_input,
&relay->text_input_new);
relay->input_method_new.notify = relay_handle_input_method_new; relay->input_method_new.notify = relay_handle_input_method_new;
wl_signal_add(&input_method_manager->events.input_method, wl_signal_add(&input_method_manager->events.input_method,
@@ -715,13 +718,13 @@ void dwl_input_method_relay_set_focus(struct dwl_input_method_relay *relay,
} }
} }
if (surface && wl_resource_get_client(text_input->input->resource) == if (surface
wl_resource_get_client(surface->resource)) { && wl_resource_get_client(text_input->input->resource)
== wl_resource_get_client(surface->resource)) {
if (relay->input_method) { if (relay->input_method) {
wlr_text_input_v3_send_enter(text_input->input, surface); wlr_text_input_v3_send_enter(text_input->input, surface);
wlr_log(WLR_INFO, "wlr_text_input_send_enter"); wlr_log(WLR_INFO, "wlr_text_input_send_enter");
if (relay->popup) if (relay->popup) input_popup_update(relay->popup);
input_popup_update(relay->popup);
} else { } else {
text_input_set_pending_focused_surface(text_input, surface); text_input_set_pending_focused_surface(text_input, surface);
} }

View File

@@ -69,32 +69,16 @@ See below for more features.
yay -S glibc wayland libinput libdrm pixman libxkbcommon git meson ninja wayland-protocols libdisplay-info libliftoff hwdata seatd yay -S glibc wayland libinput libdrm pixman libxkbcommon git meson ninja wayland-protocols libdisplay-info libliftoff hwdata seatd
``` ```
## stable - wlroots(0.17) ## arch
```bash
Since 0.18 has some bugs that affect the experience, yay -S maomaowm-git
I chose the more stable 0.17.4.
```
git clone -b 0.17.4 https://gitlab.freedesktop.org/wlroots/wlroots.git
cd wlroots
meson build -Dprefix=/usr
sudo ninja -C build install
git clone https://github.com/DreamMaoMao/maomaowm.git
cd maomaowm
meson build -Dprefix=/usr
sudo ninja -C build install
``` ```
## unstable wlroots(0.19) ## other
```bash
This is the latest version of wlroots, it doesn't own enough test.
you can try it out if you want to help to test.
```
yay -S wlroots-git yay -S wlroots-git
git clone -b wlroots-0.19 https://github.com/DreamMaoMao/maomaowm.git git clone https://github.com/DreamMaoMao/maomaowm.git
cd maomaowm cd maomaowm
meson build -Dprefix=/usr meson build -Dprefix=/usr
sudo ninja -C build install sudo ninja -C build install

230
client.h
View File

@@ -6,14 +6,18 @@
*/ */
/* Leave these functions first; they're used in the others */ /* Leave these functions first; they're used in the others */
static inline int client_is_x11(Client *c) { static inline int
client_is_x11(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
return c->type == X11; return c->type == X11;
#endif #endif
return 0; return 0;
} }
static inline struct wlr_surface *client_surface(Client *c) { static inline struct wlr_surface *
client_surface(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return c->surface.xwayland->surface; return c->surface.xwayland->surface;
@@ -21,8 +25,9 @@ static inline struct wlr_surface *client_surface(Client *c) {
return c->surface.xdg->surface; return c->surface.xdg->surface;
} }
static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, static inline int
LayerSurface **pl) { toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
{
struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface; struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
struct wlr_surface *root_surface; struct wlr_surface *root_surface;
struct wlr_layer_surface_v1 *layer_surface; struct wlr_layer_surface_v1 *layer_surface;
@@ -45,8 +50,7 @@ static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc,
} }
#endif #endif
if ((layer_surface = if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
l = layer_surface->data; l = layer_surface->data;
type = LayerShell; type = LayerShell;
goto end; goto end;
@@ -60,8 +64,7 @@ static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc,
if (!xdg_surface->popup || !xdg_surface->popup->parent) if (!xdg_surface->popup || !xdg_surface->popup->parent)
return -1; return -1;
tmp_xdg_surface = tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
if (!tmp_xdg_surface) if (!tmp_xdg_surface)
return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl); return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
@@ -86,8 +89,9 @@ end:
} }
/* The others */ /* The others */
static inline void client_activate_surface(struct wlr_surface *s, static inline void
int activated) { client_activate_surface(struct wlr_surface *s, int activated)
{
struct wlr_xdg_toplevel *toplevel; struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND #ifdef XWAYLAND
struct wlr_xwayland_surface *xsurface; struct wlr_xwayland_surface *xsurface;
@@ -100,16 +104,16 @@ static inline void client_activate_surface(struct wlr_surface *s,
wlr_xdg_toplevel_set_activated(toplevel, activated); wlr_xdg_toplevel_set_activated(toplevel, activated);
} }
static inline uint32_t client_set_bounds(Client *c, int32_t width, static inline uint32_t
int32_t height) { client_set_bounds(Client *c, int32_t width, int32_t height)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return 0; return 0;
#endif #endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0
width >= 0 && height >= 0 && && (c->bounds.width != width || c->bounds.height != height)) {
(c->bounds.width != width || c->bounds.height != height)) {
c->bounds.width = width; c->bounds.width = width;
c->bounds.height = height; c->bounds.height = height;
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height); return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
@@ -117,16 +121,31 @@ static inline uint32_t client_set_bounds(Client *c, int32_t width,
return 0; return 0;
} }
static inline const char *client_get_appid(Client *c) { static inline const char *
client_get_appid(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return c->surface.xwayland->class; return c->surface.xwayland->class ? c->surface.xwayland->class : "broken";
#endif #endif
return c->surface.xdg->toplevel->app_id; return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken";
} }
static inline void client_get_clip(Client *c, struct wlr_box *clip) { static inline int
struct wlr_box xdg_geom = {0}; client_get_pid(Client *c)
{
pid_t pid;
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->pid;
#endif
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
return pid;
}
static inline void
client_get_clip(Client *c, struct wlr_box *clip)
{
*clip = (struct wlr_box){ *clip = (struct wlr_box){
.x = 0, .x = 0,
.y = 0, .y = 0,
@@ -139,12 +158,13 @@ static inline void client_get_clip(Client *c, struct wlr_box *clip) {
return; return;
#endif #endif
wlr_xdg_surface_get_geometry(c->surface.xdg, &xdg_geom); clip->x = c->surface.xdg->geometry.x;
clip->x = xdg_geom.x; clip->y = c->surface.xdg->geometry.y;
clip->y = xdg_geom.y;
} }
static inline void client_get_geometry(Client *c, struct wlr_box *geom) { static inline void
client_get_geometry(Client *c, struct wlr_box *geom)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
geom->x = c->surface.xwayland->x; geom->x = c->surface.xwayland->x;
@@ -154,10 +174,12 @@ static inline void client_get_geometry(Client *c, struct wlr_box *geom) {
return; return;
} }
#endif #endif
wlr_xdg_surface_get_geometry(c->surface.xdg, geom); *geom = c->surface.xdg->geometry;
} }
static inline Client *client_get_parent(Client *c) { static inline Client *
client_get_parent(Client *c)
{
Client *p = NULL; Client *p = NULL;
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
@@ -167,12 +189,13 @@ static inline Client *client_get_parent(Client *c) {
} }
#endif #endif
if (c->surface.xdg->toplevel->parent) if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
&p, NULL);
return p; return p;
} }
static inline int client_has_children(Client *c) { static inline int
client_has_children(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return !wl_list_empty(&c->surface.xwayland->children); return !wl_list_empty(&c->surface.xwayland->children);
@@ -182,15 +205,19 @@ static inline int client_has_children(Client *c) {
return wl_list_length(&c->surface.xdg->link) > 1; return wl_list_length(&c->surface.xdg->link) > 1;
} }
static inline const char *client_get_title(Client *c) { static inline const char *
client_get_title(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return c->surface.xwayland->title; return c->surface.xwayland->title ? c->surface.xwayland->title : "broken";
#endif #endif
return c->surface.xdg->toplevel->title; return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title : "broken";
} }
static inline int client_is_float_type(Client *c) { static inline int
client_is_float_type(Client *c)
{
struct wlr_xdg_toplevel *toplevel; struct wlr_xdg_toplevel *toplevel;
struct wlr_xdg_toplevel_state state; struct wlr_xdg_toplevel_state state;
@@ -198,32 +225,32 @@ static inline int client_is_float_type(Client *c) {
if (client_is_x11(c)) { if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland; struct wlr_xwayland_surface *surface = c->surface.xwayland;
xcb_size_hints_t *size_hints = surface->size_hints; xcb_size_hints_t *size_hints = surface->size_hints;
size_t i;
if (surface->modal) if (surface->modal)
return 1; return 1;
for (i = 0; i < surface->window_type_len; i++) if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG)
if (surface->window_type[i] == netatom[NetWMWindowTypeDialog] || || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH)
surface->window_type[i] == netatom[NetWMWindowTypeSplash] || || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR)
surface->window_type[i] == netatom[NetWMWindowTypeToolbar] || || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
surface->window_type[i] == netatom[NetWMWindowTypeUtility])
return 1; return 1;
}
return size_hints && size_hints->min_width > 0 && return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0
size_hints->min_height > 0 && && (size_hints->max_width == size_hints->min_width
(size_hints->max_width == size_hints->min_width || || size_hints->max_height == size_hints->min_height);
size_hints->max_height == size_hints->min_height);
} }
#endif #endif
toplevel = c->surface.xdg->toplevel; toplevel = c->surface.xdg->toplevel;
state = toplevel->current; state = toplevel->current;
return toplevel->parent || (state.min_width != 0 && state.min_height != 0 && return toplevel->parent || (state.min_width != 0 && state.min_height != 0
(state.min_width == state.max_width || && (state.min_width == state.max_width
state.min_height == state.max_height)); || state.min_height == state.max_height));
} }
static inline int client_is_rendered_on_mon(Client *c, Monitor *m) { static inline int
client_is_rendered_on_mon(Client *c, Monitor *m)
{
/* This is needed for when you don't want to check formal assignment, /* This is needed for when you don't want to check formal assignment,
* but rather actual displaying of the pixels. * but rather actual displaying of the pixels.
* Usually VISIBLEON suffices and is also faster. */ * Usually VISIBLEON suffices and is also faster. */
@@ -231,12 +258,15 @@ static inline int client_is_rendered_on_mon(Client *c, Monitor *m) {
int unused_lx, unused_ly; int unused_lx, unused_ly;
if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly)) if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
return 0; return 0;
wl_list_for_each(s, &client_surface(c)->current_outputs, wl_list_for_each(s, &client_surface(c)->current_outputs, link)
link) if (s->output == m->wlr_output) return 1; if (s->output == m->wlr_output)
return 1;
return 0; return 0;
} }
static inline int client_is_stopped(Client *c) { static inline int
client_is_stopped(Client *c)
{
int pid; int pid;
siginfo_t in = {0}; siginfo_t in = {0};
#ifdef XWAYLAND #ifdef XWAYLAND
@@ -260,7 +290,9 @@ static inline int client_is_stopped(Client *c) {
return 0; return 0;
} }
static inline int client_is_unmanaged(Client *c) { static inline int
client_is_unmanaged(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return c->surface.xwayland->override_redirect; return c->surface.xwayland->override_redirect;
@@ -268,25 +300,19 @@ static inline int client_is_unmanaged(Client *c) {
return 0; return 0;
} }
static inline void client_notify_enter(struct wlr_surface *s, static inline void
struct wlr_keyboard *kb) { client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{
if (kb) if (kb)
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, kb->num_keycodes, wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes,
&kb->modifiers); kb->num_keycodes, &kb->modifiers);
else else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
} }
static inline void client_restack_surface(Client *c) { static inline void
#ifdef XWAYLAND client_send_close(Client *c)
if (client_is_x11(c)) {
wlr_xwayland_surface_restack(c->surface.xwayland, NULL,
XCB_STACK_MODE_ABOVE);
#endif
return;
}
static inline void client_send_close(Client *c) {
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
wlr_xwayland_surface_close(c->surface.xwayland); wlr_xwayland_surface_close(c->surface.xwayland);
@@ -296,26 +322,17 @@ static inline void client_send_close(Client *c) {
wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel); wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
} }
static inline int static inline void
client_get_pid(Client *c) client_set_border_color(Client *c, const float color[static 4])
{ {
pid_t pid;
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->pid;
#endif
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
return pid;
}
static inline void client_set_border_color(Client *c,
const float color[static 4]) {
int i; int i;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(c->border[i], color); wlr_scene_rect_set_color(c->border[i], color);
} }
static inline void client_set_fullscreen(Client *c, int fullscreen) { static inline void
client_set_fullscreen(Client *c, int fullscreen)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen); wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
@@ -325,42 +342,50 @@ static inline void client_set_fullscreen(Client *c, int fullscreen) {
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen); wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
} }
static inline void client_set_scale(struct wlr_surface *s, float scale) { static inline void
client_set_scale(struct wlr_surface *s, float scale)
{
wlr_fractional_scale_v1_notify_scale(s, scale); wlr_fractional_scale_v1_notify_scale(s, scale);
wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale)); wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
} }
static inline uint32_t client_set_size(Client *c, uint32_t width, static inline uint32_t
uint32_t height) { client_set_size(Client *c, uint32_t width, uint32_t height)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
wlr_xwayland_surface_configure(c->surface.xwayland, c->geom.x, c->geom.y, wlr_xwayland_surface_configure(c->surface.xwayland,
width, height); c->geom.x + c->bw, c->geom.y + c->bw, width, height);
return 0; return 0;
} }
#endif #endif
if ((int32_t)width == c->surface.xdg->toplevel->current.width && if ((int32_t)width == c->surface.xdg->toplevel->current.width
(int32_t)height == c->surface.xdg->toplevel->current.height) && (int32_t)height == c->surface.xdg->toplevel->current.height)
return 0; return 0;
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height);
(int32_t)height);
} }
static inline void client_set_tiled(Client *c, uint32_t edges) { static inline void
client_set_tiled(Client *c, uint32_t edges)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c)) {
wlr_xwayland_surface_set_maximized(c->surface.xwayland,
edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
return; return;
}
#endif #endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= if (wl_resource_get_version(c->surface.xdg->toplevel->resource)
XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) { >= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges); wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
} else { } else {
wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE);
edges != WLR_EDGE_NONE);
} }
} }
static inline void client_set_suspended(Client *c, int suspended) { static inline void
client_set_suspended(Client *c, int suspended)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return; return;
@@ -369,17 +394,20 @@ static inline void client_set_suspended(Client *c, int suspended) {
wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended); wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
} }
static inline int client_wants_focus(Client *c) { static inline int
client_wants_focus(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
return client_is_unmanaged(c) && return client_is_unmanaged(c)
wlr_xwayland_or_surface_wants_focus(c->surface.xwayland) && && wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland)
wlr_xwayland_icccm_input_model(c->surface.xwayland) != && wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
WLR_ICCCM_INPUT_MODEL_NONE;
#endif #endif
return 0; return 0;
} }
static inline int client_wants_fullscreen(Client *c) { static inline int
client_wants_fullscreen(Client *c)
{
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) if (client_is_x11(c))
return c->surface.xwayland->fullscreen; return c->surface.xwayland->fullscreen;

125
flake.lock generated
View File

@@ -1,5 +1,20 @@
{ {
"nodes": { "nodes": {
"flake-compat": {
"locked": {
"lastModified": 1717312683,
"narHash": "sha256-FrlieJH50AuvagamEvWMIE6D2OAnERuDboFDYAED/dE=",
"owner": "nix-community",
"repo": "flake-compat",
"rev": "38fd3954cf65ce6faf3d0d45cd26059e059f07ea",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
@@ -36,6 +51,43 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"lib-aggregate": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs-lib": "nixpkgs-lib_3"
},
"locked": {
"lastModified": 1742732002,
"narHash": "sha256-fznNOUwLtsnaFHIeHfmj1QxOhjiohM2oiGj/54IO+AI=",
"owner": "nix-community",
"repo": "lib-aggregate",
"rev": "00480968bd30f3f43bcd520046bb647833bf2cf2",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "lib-aggregate",
"type": "github"
}
},
"mmsg": { "mmsg": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_2", "flake-parts": "flake-parts_2",
@@ -59,11 +111,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1740019556, "lastModified": 1742800061,
"narHash": "sha256-vn285HxnnlHLWnv59Og7muqECNMS33mWLM14soFIv2g=", "narHash": "sha256-oDJGK1UMArK52vcW9S5S2apeec4rbfNELgc50LqiPNs=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dad564433178067be1fbdfcce23b546254b6d641", "rev": "1750f3c1c89488e2ffdd47cab9d05454dddfb734",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -100,14 +152,81 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib_3": {
"locked": {
"lastModified": 1742692082,
"narHash": "sha256-s3XOULQj7BVO7myY5V4Sob0tRZ7nRpwEOIzXg/MkD/Q=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a09310bc940f245e51b1ffea68731244ca38f2bd",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs-wayland": {
"inputs": {
"flake-compat": "flake-compat",
"lib-aggregate": "lib-aggregate",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1742870145,
"narHash": "sha256-ik+6+EorpRPqEVazsJhjyP9z7N83Tkq0F/Ky7GKHEso=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "b2bfc4d198ca1ff4e9278c0e984f74a6a086b2ee",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1742669843,
"narHash": "sha256-G5n+FOXLXcRx+3hCJ6Rt6ZQyF1zqQ0DL0sWAMn2Nk0w=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1e5b653dff12029333a6546c11e108ede13052eb",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"mmsg": "mmsg", "mmsg": "mmsg",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-wayland": "nixpkgs-wayland",
"treefmt-nix": "treefmt-nix" "treefmt-nix": "treefmt-nix"
} }
}, },
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [

View File

@@ -1,6 +1,7 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = { treefmt-nix = {
url = "github:numtide/treefmt-nix"; url = "github:numtide/treefmt-nix";
@@ -25,8 +26,8 @@
]; ];
flake = { flake = {
hmModules.maomaowm = import ./nix/hm-modules.nix; hmModules.maomaowm = import ./nix/hm-modules.nix self;
nixosModules.maomaowm = import ./nix/nixos-modules.nix { inherit inputs self; }; nixosModules.maomaowm = import ./nix/nixos-modules.nix self;
}; };
perSystem = perSystem =
@@ -39,7 +40,10 @@
inherit (pkgs) inherit (pkgs)
callPackage callPackage
; ;
maomaowm = callPackage ./nix { }; maomaowm = callPackage ./nix {
inherit (inputs.nixpkgs-wayland.packages.${pkgs.system}) wlroots;
inherit (inputs.mmsg.packages.${pkgs.system}) mmsg;
};
shellOverride = old: { shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ ]; nativeBuildInputs = old.nativeBuildInputs ++ [ ];
buildInputs = old.buildInputs ++ [ ]; buildInputs = old.buildInputs ++ [ ];

1470
maomao.c

File diff suppressed because it is too large Load Diff

View File

@@ -33,7 +33,7 @@ libm = cc.find_library('m')
xcb = dependency('xcb', required : get_option('xwayland')) xcb = dependency('xcb', required : get_option('xwayland'))
xlibs = dependency('xcb-icccm', required : get_option('xwayland')) xlibs = dependency('xcb-icccm', required : get_option('xwayland'))
wayland_server_dep = dependency('wayland-server') wayland_server_dep = dependency('wayland-server')
wlroots_dep = dependency('wlroots', version : ['>=0.17.0', '<0.18.0']) wlroots_dep = dependency('wlroots-0.19')
xkbcommon_dep = dependency('xkbcommon') xkbcommon_dep = dependency('xkbcommon')
libinput_dep = dependency('libinput') libinput_dep = dependency('libinput')
libwayland_client_dep = dependency('wayland-client') libwayland_client_dep = dependency('wayland-client')

View File

@@ -10,12 +10,13 @@
wayland, wayland,
wayland-protocols, wayland-protocols,
wayland-scanner, wayland-scanner,
wlroots_0_17,
xcbutilwm, xcbutilwm,
xwayland, xwayland,
enableXWayland ? true, enableXWayland ? true,
meson, meson,
ninja, ninja,
wlroots,
mmsg,
}: }:
let let
pname = "maomaowm"; pname = "maomaowm";
@@ -41,7 +42,7 @@ stdenv.mkDerivation {
pixman pixman
wayland wayland
wayland-protocols wayland-protocols
wlroots_0_17 wlroots
] ]
++ lib.optionals enableXWayland [ ++ lib.optionals enableXWayland [
libX11 libX11
@@ -51,6 +52,7 @@ stdenv.mkDerivation {
passthru = { passthru = {
providedSessions = [ "maomao" ]; providedSessions = [ "maomao" ];
inherit mmsg;
}; };
meta = { meta = {

View File

@@ -1,3 +1,4 @@
self:
{ {
lib, lib,
config, config,
@@ -5,7 +6,7 @@
... ...
}: }:
let let
maomaowm = pkgs.callPackage ./. { }; inherit (self.packages.${pkgs.system}) maomaowm;
cfg = config.wayland.windowManager.maomaowm; cfg = config.wayland.windowManager.maomaowm;
variables = lib.concatStringsSep " " cfg.systemd.variables; variables = lib.concatStringsSep " " cfg.systemd.variables;
extraCommands = lib.concatStringsSep " && " cfg.systemd.extraCommands; extraCommands = lib.concatStringsSep " && " cfg.systemd.extraCommands;

View File

@@ -1,4 +1,4 @@
{ inputs, self }: self:
{ {
config, config,
lib, lib,
@@ -7,16 +7,6 @@
}: }:
let let
cfg = config.programs.maomaowm; cfg = config.programs.maomaowm;
mmsg = lib.types.submodule {
options = {
enable = lib.mkEnableOption "Enable mmsg, the ipc for maomaowm";
package = lib.mkOption {
type = lib.types.package;
default = inputs.mmsg.packages.${pkgs.system}.mmsg;
description = "The mmsg package to use";
};
};
};
in in
{ {
options = { options = {
@@ -27,19 +17,13 @@ in
default = self.packages.${pkgs.system}.maomaowm; default = self.packages.${pkgs.system}.maomaowm;
description = "The maomaowm package to use"; description = "The maomaowm package to use";
}; };
mmsg = lib.mkOption {
type = mmsg;
default = {
enable = true;
};
description = "Options for mmsg, the ipc for maomaowm";
};
}; };
}; };
config = lib.mkMerge [ config = lib.mkIf cfg.enable {
(lib.mkIf cfg.enable { environment.systemPackages = [
environment.systemPackages = [ cfg.package ]; cfg.package
] ++ (if (builtins.hasAttr "mmsg" cfg.package) then [ cfg.package.mmsg ] else [ ]);
xdg.portal = { xdg.portal = {
enable = lib.mkDefault true; enable = lib.mkDefault true;
@@ -59,10 +43,5 @@ in
graphical-desktop.enable = lib.mkDefault true; graphical-desktop.enable = lib.mkDefault true;
}; };
}) };
(lib.mkIf cfg.mmsg.enable {
environment.systemPackages = [ cfg.mmsg.package ];
})
];
} }

23
util.c
View File

@@ -3,10 +3,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include "util.h" #include "util.h"
void die(const char *fmt, ...) { void
die(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@@ -23,10 +25,27 @@ void die(const char *fmt, ...) {
exit(1); exit(1);
} }
void *ecalloc(size_t nmemb, size_t size) { void *
ecalloc(size_t nmemb, size_t size)
{
void *p; void *p;
if (!(p = calloc(nmemb, size))) if (!(p = calloc(nmemb, size)))
die("calloc:"); die("calloc:");
return p; return p;
} }
int
fd_set_nonblock(int fd) {
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
perror("fcntl(F_GETFL):");
return -1;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
perror("fcntl(F_SETFL):");
return -1;
}
return 0;
}

1
util.h
View File

@@ -2,3 +2,4 @@
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);
int fd_set_nonblock(int fd);