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

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

fix condition

  • Property mode set to 100644
File size: 4.0 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 <bool.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
49#define NAME "vlaunch"
50
51static char *winreg = NULL;
52
53static int app_launch(const char *app)
54{
55 int rc;
56 printf("%s: Spawning %s %s \n", NAME, app, winreg);
57
58 task_id_t id;
59 task_exit_t texit;
60 int retval;
61 rc = task_spawnl(&id, app, app, winreg, NULL);
62 if (rc != EOK) {
63 printf("%s: Error spawning %s %s (%s)\n", NAME, app,
64 winreg, str_error(rc));
65 return -1;
66 }
67 rc = task_wait(id, &texit, &retval);
68 if (rc != EOK || texit != TASK_EXIT_NORMAL) {
69 printf("%s: Error retrieving retval from %s (%s)\n", NAME,
70 app, str_error(rc));
71 return -1;
72 }
73
74 return retval;
75}
76
77static void on_vterm(widget_t *widget, void *data)
78{
79 app_launch("/app/vterm");
80}
81
82static void on_vdemo(widget_t *widget, void *data)
83{
84 app_launch("/app/vdemo");
85}
86
87static void on_vlaunch(widget_t *widget, void *data)
88{
89 app_launch("/app/vlaunch");
90}
91
92int main(int argc, char *argv[])
93{
94 if (argc < 2) {
95 printf("Compositor server not specified.\n");
96 return 1;
97 }
98
99 winreg = argv[1];
100 window_t *main_window = window_open(argv[1], true, true, "vlaunch");
101 if (!main_window) {
102 printf("Cannot open main window.\n");
103 return 1;
104 }
105
106 pixel_t grd_bg = PIXEL(255, 240, 240, 240);
107 pixel_t btn_bg = PIXEL(255, 0, 0, 0);
108 pixel_t btn_fg = PIXEL(255, 240, 240, 240);
109 pixel_t lbl_bg = PIXEL(255, 240, 240, 240);
110 pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
111
112 label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
113 lbl_bg, lbl_fg);
114 button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
115 btn_fg);
116 button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
117 btn_fg);
118 button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
119 btn_fg);
120 grid_t *grid = create_grid(window_root(main_window), 4, 1, grd_bg);
121
122 if ((!lbl_caption) || (!btn_vterm) || (!btn_vdemo) ||
123 (!btn_vlaunch) || (!grid)) {
124 window_close(main_window);
125 printf("Cannot create widgets.\n");
126 return 1;
127 }
128
129 sig_connect(&btn_vterm->clicked, NULL, on_vterm);
130 sig_connect(&btn_vdemo->clicked, NULL, on_vdemo);
131 sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
132
133 grid->add(grid, &lbl_caption->widget, 0, 0, 1, 1);
134 grid->add(grid, &btn_vterm->widget, 1, 0, 1, 1);
135 grid->add(grid, &btn_vdemo->widget, 2, 0, 1, 1);
136 grid->add(grid, &btn_vlaunch->widget, 3, 0, 1, 1);
137
138 window_resize(main_window, 180, 130);
139 window_exec(main_window);
140 task_retval(0);
141 async_manager();
142
143 return 0;
144}
145
146/** @}
147 */
Note: See TracBrowser for help on using the repository browser.