source: mainline/uspace/app/vlaunch/vlaunch.c@ cd18cd1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cd18cd1 was 9e7898e, checked in by Martin Decky <martin@…>, 12 years ago

make sure the grid and label background color matches the logo background color

  • Property mode set to 100644
File size: 4.5 KB
Line 
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
35#include <stdbool.h>
36#include <errno.h>
37#include <stdio.h>
38#include <malloc.h>
39#include <io/pixel.h>
40#include <task.h>
41#include <str.h>
42#include <str_error.h>
43
44#include <window.h>
45#include <grid.h>
46#include <button.h>
47#include <label.h>
48#include <canvas.h>
49
50#include <surface.h>
51#include <source.h>
52#include <drawctx.h>
53#include <codec/tga.h>
54
55#include "images.h"
56
57#define NAME "vlaunch"
58
59#define LOGO_WIDTH 196
60#define LOGO_HEIGHT 66
61
62static char *winreg = NULL;
63
64static int app_launch(const char *app)
65{
66 int rc;
67 printf("%s: Spawning %s %s \n", NAME, app, winreg);
68
69 task_id_t id;
70 task_exit_t texit;
71 int retval;
72 rc = task_spawnl(&id, app, app, winreg, NULL);
73 if (rc != EOK) {
74 printf("%s: Error spawning %s %s (%s)\n", NAME, app,
75 winreg, str_error(rc));
76 return -1;
77 }
78 rc = task_wait(id, &texit, &retval);
79 if (rc != EOK || texit != TASK_EXIT_NORMAL) {
80 printf("%s: Error retrieving retval from %s (%s)\n", NAME,
81 app, str_error(rc));
82 return -1;
83 }
84
85 return retval;
86}
87
88static void on_vterm(widget_t *widget, void *data)
89{
90 app_launch("/app/vterm");
91}
92
93static void on_vdemo(widget_t *widget, void *data)
94{
95 app_launch("/app/vdemo");
96}
97
98static void on_vlaunch(widget_t *widget, void *data)
99{
100 app_launch("/app/vlaunch");
101}
102
103int main(int argc, char *argv[])
104{
105 if (argc < 2) {
106 printf("Compositor server not specified.\n");
107 return 1;
108 }
109
110 surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
111 if (!logo) {
112 printf("Unable to decode logo.\n");
113 return 1;
114 }
115
116 winreg = argv[1];
117 window_t *main_window = window_open(argv[1], true, true, "vlaunch", 0, 0);
118 if (!main_window) {
119 printf("Cannot open main window.\n");
120 return 1;
121 }
122
123 pixel_t grd_bg = PIXEL(255, 255, 255, 255);
124 pixel_t btn_bg = PIXEL(255, 0, 0, 0);
125 pixel_t btn_fg = PIXEL(255, 240, 240, 240);
126 pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
127 pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
128
129 canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
130 logo);
131 label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
132 lbl_bg, lbl_fg);
133 button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
134 btn_fg);
135 button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
136 btn_fg);
137 button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
138 btn_fg);
139 grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
140
141 if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
142 (!btn_vdemo) || (!btn_vlaunch) || (!grid)) {
143 window_close(main_window);
144 printf("Cannot create widgets.\n");
145 return 1;
146 }
147
148 sig_connect(&btn_vterm->clicked, NULL, on_vterm);
149 sig_connect(&btn_vdemo->clicked, NULL, on_vdemo);
150 sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
151
152 grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
153 grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1);
154 grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1);
155 grid->add(grid, &btn_vdemo->widget, 0, 3, 1, 1);
156 grid->add(grid, &btn_vlaunch->widget, 0, 4, 1, 1);
157
158 window_resize(main_window, 210, 130 + LOGO_HEIGHT);
159 window_exec(main_window);
160
161 task_retval(0);
162 async_manager();
163
164 return 0;
165}
166
167/** @}
168 */
Note: See TracBrowser for help on using the repository browser.