AglShellGrpcClient: Add support for split windows 46/29646/5 master
authorMarius Vlad <marius.vlad@collabora.com>
Thu, 25 Jan 2024 22:03:17 +0000 (00:03 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Fri, 23 Feb 2024 15:17:50 +0000 (15:17 +0000)
Bug-AGL: SPEC-4839
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I57769b64c2d4d14933f1da4930027adf9ec9f519

src/AglShellGrpcClient.cpp
src/AglShellGrpcClient.h
src/agl_shell.proto
src/main.cpp

index 6f4ff24..20a960f 100644 (file)
@@ -152,6 +152,25 @@ GrpcClient::SetAppScale(const std::string& app_id, int32_t width, int32_t height
 }
 
 
+bool
+GrpcClient::SetAppSplit(const std::string& app_id, uint32_t orientation,
+                       int32_t width, int32_t sticky, const std::string& output_name)
+{
+       agl_shell_ipc::SplitRequest request;
+
+       request.set_app_id(app_id);
+       request.set_output_name(output_name);
+       request.set_tile_orientation(orientation);
+       request.set_width(width);
+       request.set_sticky(sticky);
+
+       grpc::ClientContext context;
+       ::agl_shell_ipc::SplitResponse reply;
+
+       grpc::Status status = m_stub->SetAppSplit(&context, request, &reply);
+       return status.ok();
+}
+
 grpc::Status
 GrpcClient::Wait(void)
 {
index ff190f7..e7aa934 100644 (file)
@@ -98,6 +98,8 @@ public:
        bool SetAppNormal(const std::string& app_id);
        bool SetAppPosition(const std::string& app_id, int32_t x, int32_t y);
        bool SetAppScale(const std::string& app_id, int32_t width, int32_t height);
+       bool SetAppSplit(const std::string& app_id, uint32_t orientation,
+                        int32_t width, int32_t sticky, const std::string& output_name);
        std::vector<std::string> GetOutputs();
        void GetAppState();
        void AppStatusState(Callback callback);
index c4f3dfe..d38d896 100644 (file)
@@ -36,6 +36,9 @@ message DeactivateResponse {
 message SplitRequest {
        string app_id = 1;
        int32 tile_orientation = 2;
+       int32 width = 3;
+       int32 sticky = 4;
+       string output_name = 5;
 }
 
 message SplitResponse {
index 43e0ced..555e5a3 100644 (file)
@@ -52,6 +52,7 @@ enum action_state {
        SET_APP_ON_OUTPUT,
        SET_APP_POS,
        SET_APP_SCALE,
+       SET_APP_SPLIT,
 };
 
 static struct action {
@@ -67,6 +68,7 @@ static struct action {
        { SET_APP_ON_OUTPUT,    "ON_OUTPUT"     },
        { SET_APP_POS,          "POSITION"      },
        { SET_APP_SCALE,        "SCALE"         },
+       { SET_APP_SPLIT,        "SPLIT"         },
 };
 
 static int
@@ -91,12 +93,15 @@ run_in_thread(GrpcClient *client)
 static void
 help(char **argv)
 {
-       fprintf(stderr, "Usage: %s [-a action] [-p app_id] [-o output_name] [-l]\n",
+       fprintf(stderr, "Usage: %s [-a action] [-p app_id] [-o output_name] [-l] [-r] [-s]\n",
                        argv[0]);
-       fprintf(stderr, "\t-a -- action activate|deactivate|float|normal|getoutputs|fullscreen|on_output|position|scale\n");
+       fprintf(stderr, "\t-a -- action activate|deactivate|float|normal|getoutputs|fullscreen|on_output|position|scale|split\n");
        fprintf(stderr, "\t-p -- app_id application_id\n");
        fprintf(stderr, "\t-o -- output_name one of the outputs from getoutputs action\n");
        fprintf(stderr, "\t-l -- continuously listen for window state events\n");
+       fprintf(stderr, "\t-r -- orientation for split\n");
+       fprintf(stderr, "\t-w -- width of the window (if not specified defaults t0) for split\n");
+       fprintf(stderr, "\t-s -- sticky window for split\n");
        exit(EXIT_FAILURE);
 }
 
@@ -122,17 +127,36 @@ read_outputs(GrpcClient *client)
        fprintf(stderr, "\n");
 }
 
+static uint32_t orientation_trans(char *orientation)
+{
+       if (strcmp(orientation, "left") == 0)
+               return 1;
+       else if (strcmp(orientation, "right") == 0)
+               return 2;
+       else if (strcmp(orientation, "top") == 0)
+               return 3;
+       else if (strcmp(orientation, "bottom") == 0)
+               return 4;
+
+       return 0;
+}
+
 int main(int argc, char *argv[])
 {
        char *output = NULL;
        char *action = NULL;
        char *app_id = NULL;
+       char *orientation = NULL;
+       // none, by default
+       uint32_t orientation_translate = 0;
        int opt;
        bool listen_flag = false;
+       int width = 0;
+       int32_t sticky = 0;
        std::thread th;
 
        // app_id, output p[0] -> name, p[1] action, p[2] app_id, p[3] -> output
-       while ((opt = getopt(argc, argv, "a:p:o:lsh")) != -1) {
+       while ((opt = getopt(argc, argv, "a:p:o:r:lshw:")) != -1) {
                switch (opt) {
                case 'p':
                        app_id = optarg;
@@ -143,9 +167,18 @@ int main(int argc, char *argv[])
                case 'o':
                        output = optarg;
                        break;
+               case 'r':
+                       orientation = optarg;
+                       break;
                case 'l':
                        listen_flag = true;
                        break;
+               case 's':
+                       sticky = 1;
+                       break;
+               case 'w':
+                       width = strtoul(optarg, NULL, 10);
+                       break;
                case 'h':
                default: /* '?' */
                        help(argv);
@@ -239,6 +272,30 @@ int main(int argc, char *argv[])
                fprintf(stderr, "Set scale for  application '%s'\n", app_id);
                client->SetAppScale(std::string(app_id), 200, 200);
                break;
+       case SET_APP_SPLIT:
+               if (!orientation) {
+                       fprintf(stderr, "split require orientation\n");
+                       help(argv);
+               }
+
+               orientation_translate = orientation_trans(orientation);
+
+               if (!app_id) {
+                       fprintf(stderr, "Split require an app_id\n");
+                       help(argv);
+               }
+
+               if (!output) {
+                       fprintf(stderr, "split require an output\n");
+                       help(argv);
+               }
+
+
+               fprintf(stderr, "Set split orientation '%s' for application '%s' on output '%s'\n", 
+                               orientation, app_id, output);
+               client->SetAppSplit(std::string(app_id),
+                               orientation_translate, width, sticky, std::string(output));
+               break;
        default:
                // allow listen flag to be passed
                if (listen_flag)