[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>
|
---|
| 38 | #include <malloc.h>
|
---|
| 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 |
|
---|
[b8f1a349] | 48 | #include <surface.h>
|
---|
| 49 | #include <source.h>
|
---|
| 50 | #include <drawctx.h>
|
---|
| 51 | #include <codec/tga.h>
|
---|
| 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);
|
---|
[b5674b2] | 65 |
|
---|
[6d5e378] | 66 | task_id_t id;
|
---|
[1c635d6] | 67 | task_wait_t wait;
|
---|
| 68 | int rc = task_spawnl(&id, &wait, app, app, winreg, NULL);
|
---|
[6d5e378] | 69 | if (rc != EOK) {
|
---|
| 70 | printf("%s: Error spawning %s %s (%s)\n", NAME, app,
|
---|
| 71 | winreg, str_error(rc));
|
---|
| 72 | return -1;
|
---|
| 73 | }
|
---|
[b5674b2] | 74 |
|
---|
| 75 | task_exit_t texit;
|
---|
| 76 | int retval;
|
---|
[1c635d6] | 77 | rc = task_wait(&wait, &texit, &retval);
|
---|
[b5674b2] | 78 | if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
|
---|
[6d5e378] | 79 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
| 80 | app, str_error(rc));
|
---|
| 81 | return -1;
|
---|
| 82 | }
|
---|
[b5674b2] | 83 |
|
---|
[6d5e378] | 84 | return retval;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | static void on_vterm(widget_t *widget, void *data)
|
---|
| 88 | {
|
---|
| 89 | app_launch("/app/vterm");
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | static void on_vdemo(widget_t *widget, void *data)
|
---|
| 93 | {
|
---|
| 94 | app_launch("/app/vdemo");
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | static void on_vlaunch(widget_t *widget, void *data)
|
---|
| 98 | {
|
---|
| 99 | app_launch("/app/vlaunch");
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | int main(int argc, char *argv[])
|
---|
| 103 | {
|
---|
[87c0a45] | 104 | if (argc < 2) {
|
---|
[6d5e378] | 105 | printf("Compositor server not specified.\n");
|
---|
| 106 | return 1;
|
---|
| 107 | }
|
---|
[bdf3c0c] | 108 |
|
---|
[b8f1a349] | 109 | surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
|
---|
| 110 | if (!logo) {
|
---|
| 111 | printf("Unable to decode logo.\n");
|
---|
| 112 | return 1;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[bdf3c0c] | 115 | winreg = argv[1];
|
---|
[2c7fdaa] | 116 | window_t *main_window = window_open(argv[1],
|
---|
| 117 | WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch");
|
---|
[bdf3c0c] | 118 | if (!main_window) {
|
---|
| 119 | printf("Cannot open main window.\n");
|
---|
| 120 | return 1;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[9e7898e] | 123 | pixel_t grd_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 124 |
|
---|
| 125 | pixel_t btn_bg = PIXEL(255, 255, 255, 255);
|
---|
| 126 | pixel_t btn_fg = PIXEL(255, 186, 186, 186);
|
---|
| 127 | pixel_t btn_text = PIXEL(255, 0, 0, 0);
|
---|
| 128 |
|
---|
[9e7898e] | 129 | pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
|
---|
[296e124e] | 130 | pixel_t lbl_text = PIXEL(255, 0, 0, 0);
|
---|
[bdf3c0c] | 131 |
|
---|
[b8f1a349] | 132 | canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
|
---|
| 133 | logo);
|
---|
[bdf3c0c] | 134 | label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
|
---|
[296e124e] | 135 | lbl_bg, lbl_text);
|
---|
[bdf3c0c] | 136 | button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
|
---|
[296e124e] | 137 | btn_fg, btn_text);
|
---|
[bdf3c0c] | 138 | button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
|
---|
[296e124e] | 139 | btn_fg, btn_text);
|
---|
[bdf3c0c] | 140 | button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
|
---|
[296e124e] | 141 | btn_fg, btn_text);
|
---|
[395ca2e] | 142 | grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
|
---|
[bdf3c0c] | 143 |
|
---|
[b8f1a349] | 144 | if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
|
---|
| 145 | (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
|
---|
[bdf3c0c] | 146 | window_close(main_window);
|
---|
| 147 | printf("Cannot create widgets.\n");
|
---|
| 148 | return 1;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | sig_connect(&btn_vterm->clicked, NULL, on_vterm);
|
---|
| 152 | sig_connect(&btn_vdemo->clicked, NULL, on_vdemo);
|
---|
| 153 | sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
|
---|
| 154 |
|
---|
[b8f1a349] | 155 | grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
|
---|
[395ca2e] | 156 | grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
|
---|
| 157 | grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
|
---|
| 158 | grid->add(grid, &btn_vdemo->widget, 0, 3, 1, 1);
|
---|
| 159 | grid->add(grid, &btn_vlaunch->widget, 0, 4, 1, 1);
|
---|
[bdf3c0c] | 160 |
|
---|
[62fbb7e] | 161 | window_resize(main_window, 0, 0, 210, 130 + LOGO_HEIGHT,
|
---|
| 162 | WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
|
---|
[bdf3c0c] | 163 | window_exec(main_window);
|
---|
[b8f1a349] | 164 |
|
---|
[bdf3c0c] | 165 | task_retval(0);
|
---|
| 166 | async_manager();
|
---|
| 167 |
|
---|
| 168 | return 0;
|
---|
[6d5e378] | 169 | }
|
---|
| 170 |
|
---|
| 171 | /** @}
|
---|
| 172 | */
|
---|