Kernel/vfs - Better handling of -1 in handle list
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / main.c
1 /*
2  * Acess2 GUI (AxWin) Version 3
3  * - By John Hodge (thePowersGang)
4  *
5  * main.c
6  * - Entrypoint
7  */
8 #include <common.h>
9 #include <acess/sys.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <axwin3/keysyms.h>
13
14 // === IMPORTS ===
15 extern void     Video_Setup(void);
16 extern void     WM_Initialise(void);
17 extern int      Renderer_Menu_Init(void);
18 extern int      Renderer_Widget_Init(void);
19 extern int      Renderer_Background_Init(void);
20 extern int      Renderer_Framebuffer_Init(void);
21 extern int      Renderer_RichText_Init(void);
22 extern void     WM_Update(void);
23 extern void     WM_Hotkey_Register(int nKeys, uint32_t *Keys, const char *ActionName);
24
25 // === PROTOTYPES ===
26 void    ParseCommandline(int argc, char **argv);
27
28 // === GLOBALS ===
29 const char      *gsTerminalDevice = NULL;
30 const char      *gsMouseDevice = NULL;
31
32  int    giScreenWidth = 640;
33  int    giScreenHeight = 480;
34
35  int    giTerminalFD = -1;
36  int    giTerminalFD_Input = 0;
37  int    giMouseFD = -1;
38
39 #define __INSTALL_ROOT  "/Acess/Apps/AxWin/3.0"
40
41 const char      *gsInstallRoot = __INSTALL_ROOT;
42
43 // === CODE ===
44 /**
45  * \brief Program Entrypoint
46  */
47 int main(int argc, char *argv[])
48 {
49         ParseCommandline(argc, argv);
50         
51         if( gsTerminalDevice == NULL ) {
52                 gsTerminalDevice = "/Devices/VTerm/6";
53         }
54         if( gsMouseDevice == NULL ) {
55                 gsMouseDevice = "/Devices/Mouse/system";
56         }
57         
58         Video_Setup();
59         IPC_Init();
60         Input_Init();
61         
62         Renderer_Menu_Init();
63         Renderer_Widget_Init();
64         Renderer_Background_Init();
65         Renderer_Framebuffer_Init();
66         Renderer_RichText_Init();
67         WM_Initialise();
68
69         // TODO: Config
70         uint32_t        keys[4];
71         keys[0] = KEYSYM_LEFTGUI;       keys[1] = KEYSYM_r;
72         WM_Hotkey_Register(2, keys, "Interface>Run");
73         
74         // Spawn interface root
75         {
76                 int     server_tid = gettid();
77                 _SysDebug("server_tid = %i", server_tid);
78                 static char csInterfaceApp[] = __INSTALL_ROOT"/AxWinUI";
79                 char    server_info[] = "AXWIN3_SERVER=00000";
80                 const char      *envp[] = {server_info, NULL};
81                 const char      *argv[] = {csInterfaceApp, NULL};
82                 _SysDebug("server_tid = %i, &server_tid = %p", server_tid, &server_tid);
83                 sprintf(server_info, "AXWIN3_SERVER=%i", server_tid);
84                 // TODO: Does the client need FDs?
85                  int    rv = _SysSpawn(csInterfaceApp, argv, envp, 0, NULL, NULL);
86                 if( rv < 0 ) {
87                         _SysDebug("_SysSpawn chucked a sad, rv=%i, errno=%i", rv, _errno);
88                 }
89         }
90
91         // Main Loop
92         for(;;)
93         {
94                 fd_set  fds;
95                  int    nfds = 0;
96                 FD_ZERO(&fds);
97         
98                 WM_Update();
99
100                 Input_FillSelect(&nfds, &fds);
101                 IPC_FillSelect(&nfds, &fds);
102                 
103                 nfds ++;
104                 if( _SysSelect(nfds, &fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG) == -1 ) {
105                         _SysDebug("ERROR: select() returned -1");
106                         return -1;
107                 }
108
109                 Input_HandleSelect(&fds);
110                 IPC_HandleSelect(&fds);
111         }
112         return 0;
113 }
114
115 void ParseCommandline(int argc, char **argv)
116 {
117         
118 }
119

UCC git Repository :: git.ucc.asn.au