fbui | Framebuffer-based graphical environment |
| download: https://git.y1.nz/archives/fbui.tar.gz | |
| README | Files | Log | Refs |
libfbui/Start/main.c
1
2 /*=========================================================================
3 *
4 * fbstart, a simple button FBUI program to launch another FBUI program
5 * Copyright (C) 2004 Zachary T Smith, fbui@comcast.net
6 *
7 * This module is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This module is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this module; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * (See the file COPYING in the main directory of this archive for
22 * more details.)
23 *
24 *=======================================================================*/
25
26
27 typedef unsigned long u32;
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <sys/ioctl.h>
34 #include <linux/fb.h>
35 #include <sys/mman.h>
36 #include <unistd.h>
37 #include <string.h>
38
39 #include <linux/vt.h>
40 #include <linux/input.h>
41
42 #include "libfbui.h"
43
44
45 int
46 main(int argc, char** argv)
47 {
48 Display *dpy;
49 Window *win;
50 Font *pcf = font_new ();
51 u32 fg,bg;
52 char *program = "fblauncher";
53
54 if (!pcf_read (pcf, "ncenBI14.pcf")) {
55 font_free (pcf);
56 FATAL ("cannot load font");
57 }
58
59 short line_height = pcf->ascent + pcf->descent;
60
61 fg = 0x5000;
62 bg = 0x40ff40;
63
64 short maxwidth, a,d;
65 font_string_dims (pcf, "~Start~", &maxwidth, &a, &d);
66
67 short win_w, win_h;
68 dpy = fbui_display_open ();
69 if (!dpy)
70 FATAL ("cannot open display");
71
72 win = fbui_window_open (dpy, maxwidth,50, &win_w, &win_h, maxwidth, line_height*2,
73 0, -1,
74 &fg, &bg,
75 "fbstart", "",
76 FBUI_PROGTYPE_LAUNCHER,
77 false,false,
78 -1,
79 false, // doesn't need keys: buttons only
80 false,
81 false,
82 argc,argv);
83 if (!win)
84 FATAL ("cannot create window");
85
86 while (1) {
87 int need_redraw=0;
88 Event ev;
89
90 int err;
91 if (err = fbui_wait_event (dpy, &ev, FBUI_EVENTMASK_ALL))
92 {
93 if (err != FBUI_ERR_NOEVENT)
94 fbui_print_error (err);
95 continue;
96 }
97
98 int num = ev.type;
99
100 switch (num) {
101 case FBUI_EVENT_EXPOSE:
102 need_redraw=1;
103 break;
104
105 case FBUI_EVENT_MOVE_RESIZE:
106 win_w = ev.width;
107 win_h = ev.height;
108 need_redraw=1;
109 break;
110
111 case FBUI_EVENT_BUTTON:
112 if (ev.key & FBUI_BUTTON_LEFT) {
113 if (ev.key & 1) {
114 if (!fork()) {
115 system (program);
116 goto done;
117 }
118 }
119 }
120 break;
121 }
122
123 if (!need_redraw)
124 continue;
125
126 char text[100];
127 sprintf (text, "Start");
128
129 short w,a,d;
130 font_string_dims(pcf,text,&w,&a,&d);
131
132 int x, y;
133 x = (win_w - w) / 2;
134 if (d < 0)
135 d = -d;
136 y = (win_h - (a+d)) / 2;
137
138 fbui_clear (dpy, win);
139 fbui_draw_string (dpy, win, pcf, x,y, text, fg);
140 }
141
142 done:
143 fbui_window_close(dpy, win);
144 fbui_display_close (dpy);
145 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.