Merge branch 'master' of git://localhost/acess2
[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 void     WM_Update(void);
22 extern void     WM_Hotkey_Register(int nKeys, uint32_t *Keys, const char *ActionName);
23
24 // === PROTOTYPES ===
25 void    ParseCommandline(int argc, char **argv);
26
27 // === GLOBALS ===
28 const char      *gsTerminalDevice = NULL;
29 const char      *gsMouseDevice = NULL;
30
31  int    giScreenWidth = 640;
32  int    giScreenHeight = 480;
33
34  int    giTerminalFD = -1;
35  int    giTerminalFD_Input = 0;
36  int    giMouseFD = -1;
37
38 #define __INSTALL_ROOT  "/Acess/Apps/AxWin/3.0"
39
40 const char      *gsInstallRoot = __INSTALL_ROOT;
41
42 // === CODE ===
43 /**
44  * \brief Program Entrypoint
45  */
46 int main(int argc, char *argv[])
47 {
48          int    server_tid = gettid();
49         
50         ParseCommandline(argc, argv);
51         
52         if( gsTerminalDevice == NULL ) {
53                 gsTerminalDevice = "/Devices/VTerm/6";
54         }
55         if( gsMouseDevice == NULL ) {
56                 gsMouseDevice = "/Devices/Mouse/system";
57         }
58         
59         Video_Setup();
60         IPC_Init();
61         Input_Init();
62         
63         Renderer_Menu_Init();
64         Renderer_Widget_Init();
65         Renderer_Background_Init();
66         Renderer_Framebuffer_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         if( clone(CLONE_VM, 0) == 0 )
76         {
77                 static char csInterfaceApp[] = __INSTALL_ROOT"/AxWinUI";
78                 char    server_info[] = "AXWIN3_SERVER=00000";
79                 char    *envp[] = {server_info, NULL};
80                 char    *argv[] = {csInterfaceApp, NULL};
81                 _SysDebug("server_tid = %i, &server_tid = %p", server_tid, &server_tid);
82                 sprintf(server_info, "AXWIN3_SERVER=%i", server_tid);
83                 execve(csInterfaceApp, argv, envp);
84                 exit(1);
85         }
86
87         // Main Loop
88         for(;;)
89         {
90                 fd_set  fds;
91                  int    nfds = 0;
92                 FD_ZERO(&fds);
93         
94                 WM_Update();
95
96                 Input_FillSelect(&nfds, &fds);
97                 IPC_FillSelect(&nfds, &fds);
98                 
99                 nfds ++;
100                 if( _SysSelect(nfds, &fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG) == -1 ) {
101                         _SysDebug("ERROR: select() returned -1");
102                         return -1;
103                 }
104
105                 Input_HandleSelect(&fds);
106                 IPC_HandleSelect(&fds);
107         }
108         return 0;
109 }
110
111 void ParseCommandline(int argc, char **argv)
112 {
113         
114 }
115

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