summaryrefslogtreecommitdiff
path: root/Sources/Compositor/OwlSubsurface.m
blob: 924c2446f2b02169f757459f73d02d718ea6b12d (plain)
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
/* This file is part of Owl.
 *
 * Copyright © 2019-2021 Sergey Bugaev <bugaevc@gmail.com>
 *
 * Owl is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * Owl is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Owl.  If not, see <http://www.gnu.org/licenses/>.
 */

#import "OwlSubsurface.h"
#import "OwlSurface.h"
#import "OwlServer.h"
#import <wayland-server.h>

@implementation OwlSubsurface

static void subsurface_destroy_handler(
    struct wl_client *client,
    struct wl_resource *resource
) {
    wl_resource_destroy(resource);
}

static void subsurface_destroy(struct wl_resource *resource) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    [self unmap];
    [self->_surface setRole: nil];
    [self release];
}

static void subsurface_set_position_handler(
    struct wl_client *client,
    struct wl_resource *resource,
    int32_t x,
    int32_t y
) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    self->_position = NSMakePoint(x, y);
}

static void subsurface_place_above_handler(
    struct wl_client *client,
    struct wl_resource *resource,
    struct wl_resource *sibling_resource
) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    // TODO
}

static void subsurface_place_below_handler(
    struct wl_client *client,
    struct wl_resource *resource,
    struct wl_resource *sibling_resource
) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    // TODO
}

static void subsurface_set_sync_handler(
    struct wl_client *client,
    struct wl_resource *resource
) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    // TODO
}

static void subsurface_set_desync_handler(
    struct wl_client *client,
    struct wl_resource *resource
) {
    OwlSubsurface *self = wl_resource_get_user_data(resource);
    // TODO
}

static const struct wl_subsurface_interface subsurface_impl = {
    .destroy = subsurface_destroy_handler,
    .set_position = subsurface_set_position_handler,
    .place_above = subsurface_place_above_handler,
    .place_below = subsurface_place_below_handler,
    .set_sync = subsurface_set_sync_handler,
    .set_desync = subsurface_set_desync_handler
};

- (id) initWithResource: (struct wl_resource *) resource
                surface: (OwlSurface *) surface
                 parent: (OwlSurface *) parent
{
    _resource = resource;
    _surface = [surface retain];
    _parent = [parent retain];
    [surface setRole: self];

    wl_resource_set_implementation(
        resource,
        &subsurface_impl,
        [self retain],
        subsurface_destroy
    );

    return self;
}

- (void) dealloc {
    [self unmap];
    [_surface release];
    [_parent release];
    [super dealloc];
}

// FIXME: These are supposed to be applied on parent's next commit.
- (void) map {
    [_parent addSubview: _surface];
    [self update];
}

- (void) unmap {
    [_surface removeFromSuperview];
}

- (void) update {
    NSPoint origin;
    origin.x = _position.x;
    origin.y = [_parent frame].size.height - [_surface frame].size.height - _position.y;
    [_surface setFrameOrigin: origin];
}

@end