Skip to content

Commit c7066de

Browse files
authored
Merge pull request #338 from WayfireWM/ai-is-so-cool
Update for new wayfire API.
2 parents a65af25 + 9742934 commit c7066de

20 files changed

Lines changed: 182 additions & 220 deletions

metadata/crosshair.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<_short>Crosshair</_short>
55
<_long>Render fullscreen mouse crosshair</_long>
66
<category>Utility</category>
7-
<option name="line_width" type="int">
7+
<option name="line_width" type="double">
88
<_short>Line Width</_short>
99
<_long>Line width of crosshair</_long>
1010
<default>2</default>

src/annotate.cpp

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,23 @@ class simple_node_render_instance_t : public render_instance_t
8080
node_t *self;
8181
damage_callback push_to_parent;
8282
std::shared_ptr<anno_ws_overlay> overlay, shape_overlay;
83-
int *x, *y, *w, *h;
83+
wf::geometry_t *geometry;
8484

8585
public:
8686
simple_node_render_instance_t(node_t *self, damage_callback push_dmg,
87-
int *x, int *y, int *w, int *h, std::shared_ptr<anno_ws_overlay> overlay,
87+
wf::geometry_t *geometry, std::shared_ptr<anno_ws_overlay> overlay,
8888
std::shared_ptr<anno_ws_overlay> shape_overlay)
8989
{
90-
this->x = x;
91-
this->y = y;
92-
this->w = w;
93-
this->h = h;
94-
this->self = self;
95-
this->overlay = overlay;
90+
this->geometry = geometry;
91+
this->self = self;
92+
this->overlay = overlay;
9693
this->shape_overlay = shape_overlay;
9794
this->push_to_parent = push_dmg;
9895
self->connect(&on_node_damaged);
9996
}
10097

10198
void schedule_instructions(std::vector<render_instruction_t>& instructions,
102-
const wf::render_target_t& target, wf::region_t& damage) override
99+
const wf::render_target_t& target, wf::regionf_t& damage) override
103100
{
104101
// We want to render ourselves only, the node does not have children
105102
instructions.push_back(render_instruction_t{
@@ -111,15 +108,15 @@ class simple_node_render_instance_t : public render_instance_t
111108

112109
void render(const wf::scene::render_instruction_t& data) override
113110
{
114-
auto ol = this->overlay;
115-
wlr_box og = {*x, *y, *w, *h};
111+
auto ol = this->overlay;
112+
wf::geometry_t og = *geometry;
116113

117114
data.pass->custom_gles_subpass([&]
118115
{
119116
wf::gles::bind_render_buffer(data.target);
120117
for (auto& box : data.damage)
121118
{
122-
wf::gles::render_target_logic_scissor(data.target, wlr_box_from_pixman_box(box));
119+
wf::gles::render_target_logic_scissor(data.target, box);
123120
if (ol->cr)
124121
{
125122
OpenGL::render_texture(wf::gles_texture_t{ol->texture->tex}, data.target, og,
@@ -139,16 +136,16 @@ class simple_node_render_instance_t : public render_instance_t
139136

140137
class simple_node_t : public node_t
141138
{
142-
int x, y, w, h;
139+
wf::geometry_t geometry;
143140

144141
public:
145142
std::shared_ptr<anno_ws_overlay> overlay, shape_overlay;
146143
simple_node_t(int x, int y, int w, int h) : node_t(false)
147144
{
148-
this->x = x;
149-
this->y = y;
150-
this->w = w;
151-
this->h = h;
145+
this->geometry.x = x;
146+
this->geometry.y = y;
147+
this->geometry.width = w;
148+
this->geometry.height = h;
152149
overlay = std::make_shared<anno_ws_overlay>();
153150
shape_overlay = std::make_shared<anno_ws_overlay>();
154151
}
@@ -161,10 +158,10 @@ class simple_node_t : public node_t
161158
// this simple nodes does not need any transformations, so the push_damage
162159
// callback is just passed along.
163160
instances.push_back(std::make_unique<simple_node_render_instance_t>(
164-
this, push_damage, &x, &y, &w, &h, overlay, shape_overlay));
161+
this, push_damage, &geometry, overlay, shape_overlay));
165162
}
166163

167-
void do_push_damage(wf::region_t updated_region)
164+
void do_push_damage(wf::regionf_t updated_region)
168165
{
169166
node_damage_signal ev;
170167
ev.region = updated_region;
@@ -174,19 +171,19 @@ class simple_node_t : public node_t
174171
wf::geometry_t get_bounding_box() override
175172
{
176173
// Specify whatever geometry your node has
177-
return {x, y, w, h};
174+
return geometry;
178175
}
179176

180177
void set_position(int x, int y)
181178
{
182-
this->x = x;
183-
this->y = y;
179+
this->geometry.x = x;
180+
this->geometry.y = y;
184181
}
185182

186183
void set_size(int w, int h)
187184
{
188-
this->w = w;
189-
this->h = h;
185+
this->geometry.width = w;
186+
this->geometry.height = h;
190187
}
191188
};
192189

@@ -201,7 +198,7 @@ std::shared_ptr<simple_node_t> add_simple_node(wf::output_t *output, int x, int
201198
class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public wf::pointer_interaction_t
202199
{
203200
uint32_t button;
204-
wlr_box last_bbox;
201+
wf::geometry_t last_bbox;
205202
annotate_draw_method draw_method;
206203
wf::pointf_t grab_point, last_cursor;
207204
std::vector<std::vector<std::shared_ptr<simple_node_t>>> overlays;
@@ -519,15 +516,15 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
519516
cairo_line_to(cr, to.x, to.y);
520517
cairo_stroke(cr);
521518

522-
wlr_box bbox;
519+
wf::geometry_t bbox;
523520
int padding = line_width + 1;
524521
bbox.x = std::min(from.x, to.x) - padding;
525522
bbox.y = std::min(from.y, to.y) - padding;
526-
bbox.width = abs(from.x - to.x) + padding * 2;
527-
bbox.height = abs(from.y - to.y) + padding * 2;
528-
get_node_overlay()->do_push_damage(wf::region_t(bbox));
523+
bbox.width = std::abs(from.x - to.x) + padding * 2;
524+
bbox.height = std::abs(from.y - to.y) + padding * 2;
525+
get_node_overlay()->do_push_damage(wf::regionf_t(bbox));
529526
cairo_surface_upload_to_texture_with_damage(ol->cairo_surface, *ol->texture,
530-
bbox);
527+
wf::to_integer_box(bbox));
531528
}
532529

533530
bool should_damage_last()
@@ -563,14 +560,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
563560
cairo_line_to(cr, to.x, to.y);
564561
cairo_stroke(cr);
565562

566-
wlr_box bbox;
563+
wf::geometry_t bbox;
567564
int padding = line_width + 1;
568565
bbox.x = std::min(from.x, to.x) - padding;
569566
bbox.y = std::min(from.y, to.y) - padding;
570-
bbox.width = abs(from.x - to.x) + padding * 2;
571-
bbox.height = abs(from.y - to.y) + padding * 2;
567+
bbox.width = std::abs(from.x - to.x) + padding * 2;
568+
bbox.height = std::abs(from.y - to.y) + padding * 2;
572569
output->render->damage(bbox);
573-
wf::region_t damage_region{bbox};
570+
wf::regionf_t damage_region{bbox};
574571
if (damage_last_bbox)
575572
{
576573
output->render->damage(last_bbox);
@@ -579,14 +576,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
579576

580577
damage_region &= output->get_relative_geometry();
581578
auto damage_extents = damage_region.get_extents();
582-
wlr_box damage_box =
579+
auto damage_box = wf::to_integer_box(wf::geometry_t
583580
{damage_extents.x1, damage_extents.y1, damage_extents.x2 - damage_extents.x1,
584-
damage_extents.y2 - damage_extents.y1};
581+
damage_extents.y2 - damage_extents.y1});
585582
cairo_surface_upload_to_texture_with_damage(ol->cairo_surface, *ol->texture,
586583
damage_box);
587584

588-
get_node_overlay()->do_push_damage(wf::region_t(last_bbox));
589-
get_node_overlay()->do_push_damage(wf::region_t(bbox));
585+
get_node_overlay()->do_push_damage(wf::regionf_t(last_bbox));
586+
get_node_overlay()->do_push_damage(wf::regionf_t(bbox));
590587
last_bbox = bbox;
591588
}
592589

@@ -632,14 +629,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
632629
cairo_rectangle(cr, x, y, w, h);
633630
cairo_stroke(cr);
634631

635-
wlr_box bbox;
632+
wf::geometry_t bbox;
636633
int padding = line_width + 1;
637634
bbox.x = x - padding;
638635
bbox.y = y - padding;
639636
bbox.width = w + padding * 2;
640637
bbox.height = h + padding * 2;
641638
output->render->damage(bbox);
642-
wf::region_t damage_region{bbox};
639+
wf::regionf_t damage_region{bbox};
643640
if (damage_last_bbox)
644641
{
645642
output->render->damage(last_bbox);
@@ -648,14 +645,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
648645

649646
damage_region &= output->get_relative_geometry();
650647
auto damage_extents = damage_region.get_extents();
651-
wlr_box damage_box =
648+
auto damage_box = wf::to_integer_box(wf::geometry_t
652649
{damage_extents.x1, damage_extents.y1, damage_extents.x2 - damage_extents.x1,
653-
damage_extents.y2 - damage_extents.y1};
650+
damage_extents.y2 - damage_extents.y1});
654651
cairo_surface_upload_to_texture_with_damage(ol->cairo_surface, *ol->texture,
655652
damage_box);
656653

657-
get_node_overlay()->do_push_damage(wf::region_t(last_bbox));
658-
get_node_overlay()->do_push_damage(wf::region_t(bbox));
654+
get_node_overlay()->do_push_damage(wf::regionf_t(last_bbox));
655+
get_node_overlay()->do_push_damage(wf::regionf_t(bbox));
659656
last_bbox = bbox;
660657
}
661658

@@ -695,14 +692,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
695692
cairo_arc(cr, from.x, from.y, radius, 0, 2 * M_PI);
696693
cairo_stroke(cr);
697694

698-
wlr_box bbox;
695+
wf::geometry_t bbox;
699696
int padding = line_width + 1;
700697
bbox.x = (from.x - radius) - padding;
701698
bbox.y = (from.y - radius) - padding;
702699
bbox.width = (radius * 2) + padding * 2;
703700
bbox.height = (radius * 2) + padding * 2;
704701
output->render->damage(bbox);
705-
wf::region_t damage_region{bbox};
702+
wf::regionf_t damage_region{bbox};
706703
if (damage_last_bbox)
707704
{
708705
output->render->damage(last_bbox);
@@ -711,14 +708,14 @@ class wayfire_annotate_screen : public wf::per_output_plugin_instance_t, public
711708

712709
damage_region &= output->get_relative_geometry();
713710
auto damage_extents = damage_region.get_extents();
714-
wlr_box damage_box =
711+
auto damage_box = wf::to_integer_box(wf::geometry_t
715712
{damage_extents.x1, damage_extents.y1, damage_extents.x2 - damage_extents.x1,
716-
damage_extents.y2 - damage_extents.y1};
713+
damage_extents.y2 - damage_extents.y1});
717714
cairo_surface_upload_to_texture_with_damage(ol->cairo_surface, *ol->texture,
718715
damage_box);
719716

720-
get_node_overlay()->do_push_damage(wf::region_t(last_bbox));
721-
get_node_overlay()->do_push_damage(wf::region_t(bbox));
717+
get_node_overlay()->do_push_damage(wf::regionf_t(last_bbox));
718+
get_node_overlay()->do_push_damage(wf::regionf_t(bbox));
722719
last_bbox = bbox;
723720
}
724721

src/crosshair.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
class wayfire_crosshair : public wf::per_output_plugin_instance_t
3333
{
34-
wf::option_wrapper_t<int> line_width{"crosshair/line_width"};
34+
wf::option_wrapper_t<double> line_width{"crosshair/line_width"};
3535
wf::option_wrapper_t<wf::color_t> line_color{"crosshair/line_color"};
3636
wf::geometry_t geometry[2];
3737

@@ -56,9 +56,9 @@ class wayfire_crosshair : public wf::per_output_plugin_instance_t
5656
output->render->damage(geometry[1]);
5757

5858
geometry[0] =
59-
wf::geometry_t{int(oc.x - half_width), 0, line_width, og.height};
59+
wf::geometry_t{oc.x - half_width, 0, line_width, og.height};
6060
geometry[1] =
61-
wf::geometry_t{0, int(oc.y - half_width), og.width, line_width};
61+
wf::geometry_t{0, oc.y - half_width, og.width, line_width};
6262

6363
output->render->damage(geometry[0]);
6464
output->render->damage(geometry[1]);
@@ -68,17 +68,17 @@ class wayfire_crosshair : public wf::per_output_plugin_instance_t
6868
{
6969
auto target_fb = output->render->get_target_framebuffer();
7070
auto gc = wf::get_core().get_cursor_position();
71-
wf::point_t coords{(int)gc.x, (int)gc.y};
71+
wf::pointf_t coords{gc.x, gc.y};
7272

7373
if (!(output->get_layout_geometry() & coords))
7474
{
7575
return;
7676
}
7777

78-
wf::region_t region;
78+
wf::regionf_t region;
7979
region |= geometry[0];
8080
region |= geometry[1];
81-
region &= output->render->get_swap_damage();
81+
region &= target_fb.geometry_region_from_framebuffer_region(output->render->get_swap_damage());
8282

8383
auto alpha = wf::color_t(line_color).a;
8484
wf::color_t color = wf::color_t{

0 commit comments

Comments
 (0)