6dffe6b1c8c0c47005bacd19b0987368df0a9594
[src/agl-compositor.git] / grpc-proxy / shell.cpp
1 /*
2  * Copyright © 2022 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #include <cstdio>
27 #include <ctime>
28 #include <algorithm>
29 #include <cstring>
30 #include <string>
31 #include <queue>
32
33 #include "main-grpc.h"
34 #include "log.h"
35 #include "shell.h"
36
37 void
38 Shell::ActivateApp(const std::string &app_id, const std::string &output_name)
39 {
40         struct window_output *woutput, *w_output;
41         struct agl_shell *shell = this->m_shell.get();
42
43         woutput = nullptr;
44         w_output = nullptr;
45
46         wl_list_for_each(woutput, &m_shell_data->output_list, link) {
47                 if (woutput->name && !strcmp(woutput->name, output_name.c_str())) {
48                         w_output = woutput;
49                         break;
50                 }
51         }
52
53         // else, get the first one available
54         if (!w_output)
55                 w_output = wl_container_of(m_shell_data->output_list.prev,
56                                            w_output, link);
57
58         agl_shell_activate_app(shell, app_id.c_str(), w_output->output);
59         wl_display_flush(m_shell_data->wl_display);
60 }
61
62 void
63 Shell::DeactivateApp(const std::string &app_id)
64 {
65         struct agl_shell *shell = this->m_shell.get();
66
67         agl_shell_deactivate_app(shell, app_id.c_str());
68         wl_display_flush(m_shell_data->wl_display);
69 }
70
71 void
72 Shell::SetAppFloat(const std::string &app_id, int32_t x_pos, int32_t y_pos)
73 {
74         struct agl_shell *shell = this->m_shell.get();
75
76         agl_shell_set_app_float(shell, app_id.c_str(), x_pos, y_pos);
77         wl_display_flush(m_shell_data->wl_display);
78 }
79
80 void
81 Shell::SetAppNormal(const std::string &app_id)
82 {
83         struct agl_shell *shell = this->m_shell.get();
84
85         agl_shell_set_app_normal(shell, app_id.c_str());
86         wl_display_flush(m_shell_data->wl_display);
87 }
88
89 void
90 Shell::SetAppFullscreen(const std::string &app_id)
91 {
92         struct agl_shell *shell = this->m_shell.get();
93
94         agl_shell_set_app_fullscreen(shell, app_id.c_str());
95         wl_display_flush(m_shell_data->wl_display);
96 }
97
98 void
99 Shell::SetAppOnOutput(const std::string &app_id, const std::string &output)
100 {
101         struct window_output *woutput, *w_output;
102         struct agl_shell *shell = this->m_shell.get();
103
104         woutput = nullptr;
105         w_output = nullptr;
106
107         wl_list_for_each(woutput, &m_shell_data->output_list, link) {
108                 if (woutput->name && !strcmp(woutput->name, output.c_str())) {
109                         w_output = woutput;
110                         break;
111                 }
112         }
113
114         if (!w_output) {
115                 LOG("Could not found output '%s' to set the application\n", output.c_str());
116                 return;
117         }
118
119         agl_shell_set_app_output(shell, app_id.c_str(), w_output->output);
120         wl_display_flush(m_shell_data->wl_display);
121 }
122
123 void
124 Shell::SetAppPosition(const std::string &app_id, const int32_t x, const int32_t y)
125 {
126         struct agl_shell *shell = this->m_shell.get();
127
128         agl_shell_set_app_position(shell, app_id.c_str(), x, y);
129         wl_display_flush(m_shell_data->wl_display);
130 }
131
132 void
133 Shell::SetAppScale(const std::string &app_id,
134                 const int32_t width, const int32_t height)
135 {
136         struct agl_shell *shell = this->m_shell.get();
137
138         agl_shell_set_app_scale(shell, app_id.c_str(), width, height);
139         wl_display_flush(m_shell_data->wl_display);
140 }
141
142 void
143 Shell::SetAppSplit(const std::string &app_id, uint32_t orientation, uint32_t width, const std::string &output_name)
144 {
145         struct window_output *woutput, *w_output;
146         struct agl_shell *shell = this->m_shell.get();
147
148         woutput = nullptr;
149         w_output = nullptr;
150
151         wl_list_for_each(woutput, &m_shell_data->output_list, link) {
152                 if (woutput->name && !strcmp(woutput->name, output_name.c_str())) {
153                         w_output = woutput;
154                         break;
155                 }
156         }
157
158         // else, get the first one available
159         if (!w_output)
160                 w_output = wl_container_of(m_shell_data->output_list.prev,
161                                            w_output, link);
162
163
164         agl_shell_set_app_split(shell, app_id.c_str(), orientation, width, w_output->output);
165         wl_display_flush(m_shell_data->wl_display);
166 }