Skip to content

Commit

Permalink
Merge pull request #56 from werererer/development
Browse files Browse the repository at this point in the history
Update to new version of wlroots and refactor a bit
  • Loading branch information
werererer authored Dec 31, 2023
2 parents 9cdc208 + fe8f84d commit 81c7926
Show file tree
Hide file tree
Showing 32 changed files with 777 additions and 1,030 deletions.
1 change: 0 additions & 1 deletion config/layouts/tmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,3 @@ local resize_groups = {}
resize_groups[1] = {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}}
layout:set_resize_data(resize_groups)
opt.resize_direction = Direction.all
print("works")
8 changes: 4 additions & 4 deletions include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ struct client {
struct wl_listener set_app_id;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener associate;
struct wl_listener dissociate;
struct wl_listener destroy;
struct wl_listener new_popup;
struct wl_listener new_subsurface;

struct scene_surface *scene_surface;

enum shell type;
const char *title;
const char *app_id;
Expand All @@ -44,10 +48,6 @@ struct client {
// enum zwlr_layer_surface_v1_layer layer;
int layer;

// used to determine what to damage
bool resized;
bool moved_tag;
bool is_independent;
// this is currently only used for layer_shell surfaces to help determine if
// arrange_layers should be called
bool mapped;
Expand Down
17 changes: 10 additions & 7 deletions include/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ struct wlr_box get_monitor_local_box(struct wlr_box box, struct monitor *m);
struct wlr_fbox lua_togeometry(lua_State *L);

void ack_configure(struct wl_listener *listener, void *data);
struct wlr_box apply_bounds(struct container *con, struct wlr_box bbox);
void apply_bounds(struct wlr_box *geom, struct wlr_box box);
void commit_notify(struct wl_listener *listener, void *data);
void configure_notify(struct wl_listener *listener, void *data);
void container_damage_borders_at_monitor(struct container *con, struct monitor *m);
void container_damage_borders(struct container *con);
void container_damage_part(struct container *con);
void container_damage_whole(struct container *con);
void container_fix_position_to_begin(struct container *con);
void container_fix_position(struct container *con);
void focus_on_hidden_stack(struct monitor *m, int i);
Expand All @@ -104,9 +100,14 @@ void container_set_floating(struct container *con, void (*fix_position)(struct c
void container_set_hidden(struct container *con, bool b);
void container_set_hidden_at_tag(struct container *con, bool b, struct tag *tag);
void set_container_monitor(struct container *con, struct monitor *m);
void container_update_border(struct container *con);
void container_update_border_geometry(struct container *con);
void container_update_border_color(struct container *con);
void container_update_border_visibility(struct container *con);
void resize_container(struct container *con, struct wlr_cursor *cursor, int dx, int dy);
void resize_container_in_layout(struct container *con, struct wlr_box geom);
void move_container(struct container *con, struct wlr_cursor *cursor, int offsetx, int offsety);
void scale_box(struct wlr_box *box, float scale);

struct container_property *container_get_property(struct container *con);
struct container_property *container_get_property_at_tag(
Expand Down Expand Up @@ -168,8 +169,8 @@ void container_resize_with_cursor(struct cursor *cursor);

struct monitor *container_get_monitor(struct container *con);

int absolute_x_to_container_relative(struct wlr_box geom, int x);
int absolute_y_to_container_relative(struct wlr_box geom, int y);
int absolute_x_to_container_local(struct wlr_box geom, int x);
int absolute_y_to_container_local(struct wlr_box geom, int y);
int get_position_in_container_focus_stack(struct container *con);
int get_position_in_container_stack(struct container *con);

Expand All @@ -196,5 +197,7 @@ bool container_is_managed(struct container *con);
bool container_is_tiled_and_managed(struct container *con);
bool container_is_on_scratchpad(struct container *con);

struct wlr_scene_node *container_get_scene_node(struct container *con);

const char *container_get_app_id(struct container *con);
#endif /* CONTAINER_H */
5 changes: 3 additions & 2 deletions include/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MONITOR_H
#include <wayland-server.h>
#include <wlr/util/box.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_scene.h>

#include "server.h"
#include "bitset/bitset.h"
Expand All @@ -13,7 +13,6 @@ struct monitor {
struct wlr_output *wlr_output;
struct wlr_output_damage *damage;

struct wl_listener mode;
struct wl_listener frame;
struct wl_listener damage_frame;
struct wl_listener destroy;
Expand All @@ -22,6 +21,8 @@ struct monitor {
struct root *root;
float scale;

struct wlr_scene_output *scene_output;

int tag_id;
};

Expand Down
10 changes: 9 additions & 1 deletion include/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct xdg_popup {
struct container *toplevel;
struct wlr_box geom;
struct monitor *m;
void *parent;
struct wlr_scene_surface *scene_surface;

struct wl_listener map;
struct wl_listener unmap;
Expand All @@ -19,10 +21,16 @@ struct xdg_popup {
};

struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popup,
struct wlr_box parent_geom, struct container* toplevel);
void *parent, struct container* toplevel);
void popup_handle_destroy(struct wl_listener *listener, void *data);
void destroy_popups();
struct wlr_surface *get_popup_surface_under_cursor(struct cursor *cursor, double *sx, double *sy);
struct xdg_popup *get_latest_popup();
bool popups_exist();

void popup_set_x(struct xdg_popup *popup, int x);
void popup_set_y(struct xdg_popup *popup, int y);
void popup_set_width(struct xdg_popup *popup, int width);
void popup_set_height(struct xdg_popup *popup, int height);
void pupup_update_position(struct xdg_popup *popup);
#endif /* POPUP_H */
27 changes: 27 additions & 0 deletions include/render.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef RENDER_H
#define RENDER_H

#include <wlr/types/wlr_scene.h>

#include "container.h"

#define BORDER_COUNT 4

struct scene_surface {
struct wlr_surface *wlr;
struct wlr_scene_tree *surface_tree;
struct wlr_scene_surface *scene_surface;
struct wlr_scene_rect *borders[4];
struct wl_list link;

struct wl_listener commit;
struct wl_listener destroy;
struct wl_listener new_subsurface;
};

void scene_create(struct wlr_scene **scene);
void server_handle_new_surface(struct wl_listener *listener, void *data);

struct client *wlr_surface_get_client(struct wlr_surface *wlr_surface);

#endif /* RENDER_H */
34 changes: 0 additions & 34 deletions include/render/render.h

This file was deleted.

13 changes: 13 additions & 0 deletions include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <wlr/types/wlr_tablet_v2.h>
#include <glib.h>
#include <pthread.h>
#include <wlr/types/wlr_scene.h>

#include "cursor.h"
#include "layout.h"
Expand All @@ -21,6 +22,7 @@
#include "input_manager.h"
#include "utils/coreUtils.h"
#include "bitset/bitset.h"
#include "render.h"

struct server {
bool is_running;
Expand All @@ -29,6 +31,7 @@ struct server {

struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop;
struct wlr_session *wlr_session;
struct wlr_backend *backend;
struct wlr_compositor *compositor;
struct wlr_renderer *renderer;
Expand All @@ -44,6 +47,16 @@ struct server {

struct event_handler *event_handler;

struct wlr_scene *scene;
struct wlr_scene_tree *scene_background;
struct wlr_scene_tree *scene_tiled;
struct wlr_scene_tree *scene_floating;
struct wlr_scene_tree *scene_popups;
struct wlr_scene_tree *scene_overlay;


struct wl_listener new_surface;

struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
Expand Down
12 changes: 6 additions & 6 deletions include/utils/coreUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ typedef GPtrArray GPtrArray2D;
/* macros */
//NOLINTNEXTLINE
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
/* number of chars a string should contain */
#define ARR_STRING_LENGTH(X) strlen(X) + 2*(strlen("[]") + NUM_DIGITS)

// those constants are arbitrary and are bound to change
#define MAXLEN 15
Expand All @@ -42,9 +39,10 @@ typedef GPtrArray GPtrArray2D;
#define MIN_CONTAINER_HEIGHT 30
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))

#define foreach(item, array)\
for(int keep = 1, count = 0, size = LENGTH(array); keep && count < size; keep = 1, count++)\
for(item = array[count]; keep; keep = 0)\
// version management
#define WL_COMPOSITOR_VERSION 6
#define LAYER_SHELL_VERSION 4
#define XDG_SHELL_VERSION 2

extern struct lua_State *L;

Expand Down Expand Up @@ -147,7 +145,9 @@ void *get_relative_item_in_composed_list(GPtrArray *arrays, int i, int j);
int exec(const char *cmd);
bool is_approx_equal(double a, double b, double error_range);

// Converts a Lua table index (1-based) to a C array index (0-based).
int lua_idx_to_c_idx(int lua_idx);
// Converts a C array index (0-based) to a Lua table index (1-based).
int c_idx_to_lua_idx(int c_idx);

int scale_percent_to_integer(float percent);
Expand Down
1 change: 0 additions & 1 deletion include/utils/writeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <wlr/util/box.h>

#include "utils/stringUtils.h"
#include "render/render.h"

int write_to_file(int fd, const char *content);
void write_container_to_file(int fd, struct wlr_fbox box);
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ deps = [\
wayland_client,
wayland_protos,
dependency('pixman-1'),
dependency('wlroots', version: ['>=0.15' ,'<0.17']),
dependency('wlroots', version: ['>=0.15' ,'<0.18']),
dependency('x11'),
dependency('json-c'),
dependency('libnotify'),
Expand Down
25 changes: 17 additions & 8 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ struct client *create_client(enum shell shell_type, union surface_t surface)
c->type = shell_type;
c->surface = surface;

// HACK: this is a hack. first wlr_surface->data is filled with the surface
// then we will override it with the client afterwards
switch (shell_type) {
case XDG_SHELL:
c->scene_surface = surface.xdg->surface->data;
break;
case LAYER_SHELL:
c->scene_surface = surface.layer->surface->data;
break;
case X11_MANAGED:
case X11_UNMANAGED:
c->scene_surface = surface.xwayland->data;
break;
}

return c;
}

Expand Down Expand Up @@ -104,6 +119,7 @@ static void unfocus_client(struct client *c)
default:
break;
}
container_update_border_color(c->con);
}

void focus_surface(struct seat *seat, struct wlr_surface *surface)
Expand Down Expand Up @@ -131,8 +147,6 @@ void focus_client(struct seat *seat, struct client *old, struct client *c)
if (old_surface != new_surface) {
cursor_constrain(seat->cursor, NULL);
unfocus_client(old);
struct container *old_con = old->con;
container_damage_borders(old_con);
}
}

Expand All @@ -152,10 +166,6 @@ void focus_client(struct seat *seat, struct client *old, struct client *c)
/* Update wlroots'c keyboard focus */
focus_surface(seat, get_wlrsurface(c));

struct container *con = c->con;
struct monitor *m = container_get_monitor(con);
container_damage_borders_at_monitor(con, m);

/* Activate the new client */
switch (c->type) {
case XDG_SHELL:
Expand Down Expand Up @@ -208,7 +218,7 @@ void client_handle_new_popup(struct wl_listener *listener, void *data)

struct container *con = client->con;
struct monitor *m = container_get_monitor(con);
create_popup(m, xdg_popup, container_get_current_geom(con), con);
create_popup(m, xdg_popup, con, con);
}

void client_handle_set_title(struct wl_listener *listener, void *data)
Expand Down Expand Up @@ -282,6 +292,5 @@ void reset_floating_client_borders(int border_px)
continue;
}
container_set_border_width(con, direction_value_uniform(border_px));
container_damage_whole(con);
}
}
Loading

0 comments on commit 81c7926

Please sign in to comment.