summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wl2/ecore_wl2_subsurf.c
blob: 2456fd2aaa8a86c873a5101c56bece60a0d6c26b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ecore_wl2_private.h"

void
_ecore_wl2_subsurf_free(Ecore_Wl2_Subsurface *subsurf)
{
   Ecore_Wl2_Window *parent;

   if (subsurf->wl.subsurface) wl_subsurface_destroy(subsurf->wl.subsurface);
   if (subsurf->wl.surface) wl_surface_destroy(subsurf->wl.surface);

   parent = subsurf->parent;
   if (parent)
     {
        parent->subsurfs =
          eina_inlist_remove(parent->subsurfs, EINA_INLIST_GET(subsurf));
     }

   free(subsurf);
}

EAPI Ecore_Wl2_Subsurface *
ecore_wl2_subsurface_new(Ecore_Wl2_Window *window)
{
   Ecore_Wl2_Display *display;
   Ecore_Wl2_Subsurface *subsurf;

   EINA_SAFETY_ON_NULL_RETURN_VAL(window, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(window->surface, NULL);

   display = window->display;

   EINA_SAFETY_ON_NULL_RETURN_VAL(display->wl.compositor, NULL);
   EINA_SAFETY_ON_NULL_RETURN_VAL(display->wl.subcompositor, NULL);

   subsurf = calloc(1, sizeof(Ecore_Wl2_Subsurface));
   if (!subsurf) return NULL;

   subsurf->parent = window;

   subsurf->wl.surface = wl_compositor_create_surface(display->wl.compositor);
   if (!subsurf->wl.surface)
     {
        ERR("Failed to create surface: %m");
        goto surf_err;
     }

   subsurf->wl.subsurface =
     wl_subcompositor_get_subsurface(display->wl.subcompositor,
                                     subsurf->wl.surface, window->surface);
   if (!subsurf->wl.subsurface)
     {
        ERR("Could not create subsurface: %m");
        goto sub_surf_err;
     }

   window->subsurfs =
     eina_inlist_append(window->subsurfs, EINA_INLIST_GET(subsurf));

   return subsurf;

sub_surf_err:
   wl_surface_destroy(subsurf->wl.surface);

surf_err:
   free(subsurf);
   return NULL;
}

EAPI void
ecore_wl2_subsurface_del(Ecore_Wl2_Subsurface *subsurface)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);

   _ecore_wl2_subsurf_free(subsurface);
}

EAPI struct wl_surface *
ecore_wl2_subsurface_surface_get(Ecore_Wl2_Subsurface *subsurface)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(subsurface, NULL);

   return subsurface->wl.surface;
}

EAPI void
ecore_wl2_subsurface_position_set(Ecore_Wl2_Subsurface *subsurface, int x, int y)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);
   EINA_SAFETY_ON_NULL_RETURN(subsurface->wl.subsurface);

   if ((subsurface->x == x) && (subsurface->y == y)) return;

   subsurface->x = x;
   subsurface->y = y;

   wl_subsurface_set_position(subsurface->wl.subsurface, x, y);
}

EAPI void
ecore_wl2_subsurface_position_get(Ecore_Wl2_Subsurface *subsurface, int *x, int *y)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);

   if (x) *x = subsurface->x;
   if (y) *y = subsurface->y;
}

EAPI void
ecore_wl2_subsurface_place_above(Ecore_Wl2_Subsurface *subsurface, struct wl_surface *surface)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);
   EINA_SAFETY_ON_NULL_RETURN(surface);

   wl_subsurface_place_above(subsurface->wl.subsurface, surface);
}

EAPI void
ecore_wl2_subsurface_place_below(Ecore_Wl2_Subsurface *subsurface, struct wl_surface *surface)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);
   EINA_SAFETY_ON_NULL_RETURN(surface);

   wl_subsurface_place_below(subsurface->wl.subsurface, surface);
}

EAPI void
ecore_wl2_subsurface_sync_set(Ecore_Wl2_Subsurface *subsurface, Eina_Bool sync)
{
   EINA_SAFETY_ON_NULL_RETURN(subsurface);
   EINA_SAFETY_ON_NULL_RETURN(subsurface->wl.subsurface);

   sync = !!sync;
   if (subsurface->sync == sync) return;

   subsurface->sync = sync;

   if (subsurface->sync)
     wl_subsurface_set_sync(subsurface->wl.subsurface);
   else
     wl_subsurface_set_desync(subsurface->wl.subsurface);
}