[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup vlaunch
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3e6a98c5] | 35 | #include <stdbool.h>
|
---|
[6d5e378] | 36 | #include <errno.h>
|
---|
| 37 | #include <stdio.h>
|
---|
[38d150e] | 38 | #include <stdlib.h>
|
---|
[6d5e378] | 39 | #include <task.h>
|
---|
| 40 | #include <str_error.h>
|
---|
| 41 |
|
---|
| 42 | #include <window.h>
|
---|
| 43 | #include <grid.h>
|
---|
| 44 | #include <button.h>
|
---|
| 45 | #include <label.h>
|
---|
[b8f1a349] | 46 | #include <canvas.h>
|
---|
[6d5e378] | 47 |
|
---|
[2bb6d04] | 48 | #include <draw/surface.h>
|
---|
| 49 | #include <draw/source.h>
|
---|
| 50 | #include <draw/drawctx.h>
|
---|
| 51 | #include <draw/codec.h>
|
---|
[b8f1a349] | 52 |
|
---|
| 53 | #include "images.h"
|
---|
| 54 |
|
---|
| 55 | #define NAME "vlaunch"
|
---|
| 56 |
|
---|
[b4f43a1] | 57 | #define LOGO_WIDTH 196
|
---|
| 58 | #define LOGO_HEIGHT 66
|
---|
[6d5e378] | 59 |
|
---|
| 60 | static char *winreg = NULL;
|
---|
| 61 |
|
---|
| 62 | static int app_launch(const char *app)
|
---|
| 63 | {
|
---|
| 64 | printf("%s: Spawning %s %s \n", NAME, app, winreg);
|
---|
[a35b458] | 65 |
|
---|
[6d5e378] | 66 | task_id_t id;
|
---|
[1c635d6] | 67 | task_wait_t wait;
|
---|
[55fe220] | 68 | task_wait_set(&wait, TASK_WAIT_RETVAL);
|
---|
[b7fd2a0] | 69 | errno_t rc = task_spawnl(&id, &wait, app, app, winreg, NULL);
|
---|
[6d5e378] | 70 | if (rc != EOK) {
|
---|
| 71 | printf("%s: Error spawning %s %s (%s)\n", NAME, app,
|
---|
| 72 | winreg, str_error(rc));
|
---|
| 73 | return -1;
|
---|
| 74 | }
|
---|
[55fe220] | 75 |
|
---|
[b5674b2] | 76 | int retval;
|
---|
[55fe220] | 77 | rc = task_wait(&wait, NULL, &retval);
|
---|
| 78 | if ((rc != EOK)) {
|
---|
[6d5e378] | 79 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
| 80 | app, str_error(rc));
|
---|
| 81 | return -1;
|
---|
| 82 | }
|
---|
[a35b458] | 83 |
|
---|
[6d5e378] | 84 | return retval;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[10cb47e] | 87 | static void on_btn_click(widget_t *widget, void *data)
|
---|
[6d5e378] | 88 | {
|
---|
[10cb47e] | 89 | const char *app = (const char *) widget_get_data(widget);
|
---|
| 90 | app_launch(app);
|
---|
[6d5e378] | 91 | }
|
---|
| 92 |
|
---|
| 93 | int main(int argc, char *argv[])
|
---|
| 94 | {
|
---|
[87c0a45] | 95 | if (argc < 2) {
|
---|
[6d5e378] | 96 | printf("Compositor server not specified.\n");
|
---|
| 97 | return 1;
|
---|
| 98 | }
|
---|
[a35b458] | 99 |
|
---|
[b8f1a349] | 100 | surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
|
---|
| 101 | if (!logo) {
|
---|
| 102 | printf("Unable to decode logo.\n");
|
---|
| 103 | return 1;
|
---|
| 104 | }
|
---|
[a35b458] | 105 |
|
---|
[bdf3c0c] | 106 | winreg = argv[1];
|
---|
[10cb47e] | 107 | window_t *main_window = window_open(argv[1], NULL,
|
---|
[2c7fdaa] | 108 | WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch");
|
---|
[bdf3c0c] | 109 | if (!main_window) {
|
---|
| 110 | printf("Cannot open main window.\n");
|
---|
| 111 | return 1;
|
---|
| 112 | }
|
---|
[a35b458] | 113 |
|
---|
[9e7898e] | 114 | pixel_t grd_bg = PIXEL(255, 255, 255, 255);
|
---|
[a35b458] | 115 |
|
---|
[296e124e] | 116 | pixel_t btn_bg = PIXEL(255, 255, 255, 255);
|
---|
| 117 | pixel_t btn_fg = PIXEL(255, 186, 186, 186);
|
---|
| 118 | pixel_t btn_text = PIXEL(255, 0, 0, 0);
|
---|
[a35b458] | 119 |
|
---|
[9e7898e] | 120 | pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 121 | pixel_t lbl_text = PIXEL(255, 0, 0, 0);
|
---|
[a35b458] | 122 |
|
---|
[10cb47e] | 123 | canvas_t *logo_canvas = create_canvas(NULL, NULL, LOGO_WIDTH, LOGO_HEIGHT,
|
---|
[b8f1a349] | 124 | logo);
|
---|
[10cb47e] | 125 | label_t *lbl_caption = create_label(NULL, NULL, "Launch application:",
|
---|
| 126 | 16, lbl_bg, lbl_text);
|
---|
| 127 | button_t *btn_vterm = create_button(NULL, "/app/vterm", "vterm",
|
---|
| 128 | 16, btn_bg, btn_fg, btn_text);
|
---|
[bdfdc51c] | 129 | button_t *btn_vcalc = create_button(NULL, "/app/vcalc", "vcalc",
|
---|
| 130 | 16, btn_bg, btn_fg, btn_text);
|
---|
[10cb47e] | 131 | button_t *btn_vdemo = create_button(NULL, "/app/vdemo", "vdemo",
|
---|
| 132 | 16, btn_bg, btn_fg, btn_text);
|
---|
| 133 | button_t *btn_vlaunch = create_button(NULL, "/app/vlaunch", "vlaunch",
|
---|
| 134 | 16, btn_bg, btn_fg, btn_text);
|
---|
[bdfdc51c] | 135 | grid_t *grid = create_grid(window_root(main_window), NULL, 1, 6, grd_bg);
|
---|
[a35b458] | 136 |
|
---|
[b8f1a349] | 137 | if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
|
---|
[bdfdc51c] | 138 | (!btn_vcalc) || (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
|
---|
[bdf3c0c] | 139 | window_close(main_window);
|
---|
| 140 | printf("Cannot create widgets.\n");
|
---|
| 141 | return 1;
|
---|
| 142 | }
|
---|
[a35b458] | 143 |
|
---|
[10cb47e] | 144 | sig_connect(&btn_vterm->clicked, &btn_vterm->widget, on_btn_click);
|
---|
[bdfdc51c] | 145 | sig_connect(&btn_vcalc->clicked, &btn_vcalc->widget, on_btn_click);
|
---|
[10cb47e] | 146 | sig_connect(&btn_vdemo->clicked, &btn_vdemo->widget, on_btn_click);
|
---|
| 147 | sig_connect(&btn_vlaunch->clicked, &btn_vlaunch->widget, on_btn_click);
|
---|
[a35b458] | 148 |
|
---|
[b8f1a349] | 149 | grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
|
---|
[395ca2e] | 150 | grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
|
---|
| 151 | grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
|
---|
[bdfdc51c] | 152 | grid->add(grid, &btn_vcalc->widget, 0, 3, 1, 1);
|
---|
| 153 | grid->add(grid, &btn_vdemo->widget, 0, 4, 1, 1);
|
---|
| 154 | grid->add(grid, &btn_vlaunch->widget, 0, 5, 1, 1);
|
---|
[a35b458] | 155 |
|
---|
[bdfdc51c] | 156 | window_resize(main_window, 0, 0, 210, 164 + LOGO_HEIGHT,
|
---|
[62fbb7e] | 157 | WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
|
---|
[bdf3c0c] | 158 | window_exec(main_window);
|
---|
[a35b458] | 159 |
|
---|
[bdf3c0c] | 160 | task_retval(0);
|
---|
| 161 | async_manager();
|
---|
[a35b458] | 162 |
|
---|
[bdf3c0c] | 163 | return 0;
|
---|
[6d5e378] | 164 | }
|
---|
| 165 |
|
---|
| 166 | /** @}
|
---|
| 167 | */
|
---|