/*
|
/*
|
* Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
|
* Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
|
*
|
*
|
* Main module of Microwindows
|
* Main module of Microwindows
|
*/
|
*/
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <string.h>
|
#include <signal.h>
|
#include <signal.h>
|
|
|
#ifndef __PACIFIC__
|
#ifndef __PACIFIC__
|
#include <errno.h>
|
#include <errno.h>
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#endif
|
#endif
|
|
|
#if UNIX | DOS_DJGPP
|
#if UNIX | DOS_DJGPP
|
#include <unistd.h>
|
#include <unistd.h>
|
#if _MINIX
|
#if _MINIX
|
#include <sys/times.h>
|
#include <sys/times.h>
|
#else
|
#else
|
#include <sys/time.h>
|
#include <sys/time.h>
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
#if ELKS
|
#if ELKS
|
#include <linuxmt/posix_types.h>
|
#include <linuxmt/posix_types.h>
|
#include <linuxmt/time.h>
|
#include <linuxmt/time.h>
|
#endif
|
#endif
|
|
|
#include "windows.h"
|
#include "windows.h"
|
#include "wintern.h"
|
#include "wintern.h"
|
#include "device.h"
|
#include "device.h"
|
/*
|
/*
|
* External definitions defined here.
|
* External definitions defined here.
|
*/
|
*/
|
HWND listwp; /* list of all windows */
|
HWND listwp; /* list of all windows */
|
HWND rootwp; /* root window pointer */
|
HWND rootwp; /* root window pointer */
|
HWND focuswp; /* focus window for keyboard */
|
HWND focuswp; /* focus window for keyboard */
|
HWND mousewp; /* window mouse is currently in */
|
HWND mousewp; /* window mouse is currently in */
|
HWND capturewp; /* capture window*/
|
HWND capturewp; /* capture window*/
|
HWND dragwp; /* window user is dragging*/
|
HWND dragwp; /* window user is dragging*/
|
HCURSOR curcursor; /* currently enabled cursor */
|
HCURSOR curcursor; /* currently enabled cursor */
|
MWCOORD cursorx; /* current x position of cursor */
|
MWCOORD cursorx; /* current x position of cursor */
|
MWCOORD cursory; /* current y position of cursor */
|
MWCOORD cursory; /* current y position of cursor */
|
DWORD startTicks; /* tickcount on startup */
|
DWORD startTicks; /* tickcount on startup */
|
int keyb_fd; /* the keyboard file descriptor */
|
int keyb_fd; /* the keyboard file descriptor */
|
int mouse_fd; /* the mouse file descriptor */
|
int mouse_fd; /* the mouse file descriptor */
|
int escape_quits = 1; /* terminate when pressing ESC */
|
int escape_quits = 1; /* terminate when pressing ESC */
|
|
|
int
|
int
|
main(int ac,char **av)
|
main(int ac,char **av)
|
{
|
{
|
/* call user hook routine before anything*/
|
/* call user hook routine before anything*/
|
if(MwUserInit(ac, av) < 0)
|
if(MwUserInit(ac, av) < 0)
|
exit(1);
|
exit(1);
|
|
|
if(MwOpen() < 0)
|
if(MwOpen() < 0)
|
exit(1);
|
exit(1);
|
|
|
/* call windows main program entry point*/
|
/* call windows main program entry point*/
|
WinMain(NULL, NULL, NULL, SW_SHOW);
|
WinMain(NULL, NULL, NULL, SW_SHOW);
|
|
|
MwClose();
|
MwClose();
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* Open a connection from a new client to the server.
|
* Open a connection from a new client to the server.
|
* Returns -1 on failure.
|
* Returns -1 on failure.
|
*/
|
*/
|
int
|
int
|
MwOpen(void)
|
MwOpen(void)
|
{
|
{
|
/* Client calls this routine once. We
|
/* Client calls this routine once. We
|
* init everything here
|
* init everything here
|
*/
|
*/
|
if(MwInitialize() < 0)
|
if(MwInitialize() < 0)
|
return -1;
|
return -1;
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/*
|
/*
|
* Close the connection to the server.
|
* Close the connection to the server.
|
*/
|
*/
|
void
|
void
|
MwClose(void)
|
MwClose(void)
|
{
|
{
|
MwTerminate();
|
MwTerminate();
|
}
|
}
|
|
|
#if (UNIX | DOS_DJGPP) && !_MINIX
|
#if (UNIX | DOS_DJGPP) && !_MINIX
|
/*
|
/*
|
* Support for more than one user fd.
|
* Support for more than one user fd.
|
* Chris Johns (ccj@acm.org)
|
* Chris Johns (ccj@acm.org)
|
*
|
*
|
* Register the specified file descriptor to post
|
* Register the specified file descriptor to post
|
* WM_FDINPUT/WM_FDOUTPUT/WM_FDEXCEPT to the passed hwnd
|
* WM_FDINPUT/WM_FDOUTPUT/WM_FDEXCEPT to the passed hwnd
|
* when input/output/except is ready.
|
* when input/output/except is ready.
|
*
|
*
|
* Allow for any fd to be selected on.
|
* Allow for any fd to be selected on.
|
*
|
*
|
* The user fd's are listed and scanned helping keep the
|
* The user fd's are listed and scanned helping keep the
|
* overhead down for a large list of fd's being selected on.
|
* overhead down for a large list of fd's being selected on.
|
*/
|
*/
|
|
|
typedef struct {
|
typedef struct {
|
HWND read;
|
HWND read;
|
HWND write;
|
HWND write;
|
HWND except;
|
HWND except;
|
int next;
|
int next;
|
} WNDUSERFD;
|
} WNDUSERFD;
|
|
|
static WNDUSERFD userregfd[FD_SETSIZE];
|
static WNDUSERFD userregfd[FD_SETSIZE];
|
static int userregfd_head;
|
static int userregfd_head;
|
|
|
void
|
void
|
MwRegisterFdInput(HWND hwnd, int fd)
|
MwRegisterFdInput(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (!userregfd[fd].read) {
|
if (!userregfd[fd].read) {
|
userregfd[fd].read = hwnd;
|
userregfd[fd].read = hwnd;
|
if (userregfd[fd].next == -1 && !userregfd[fd].write && !userregfd[fd].except) {
|
if (userregfd[fd].next == -1 && !userregfd[fd].write && !userregfd[fd].except) {
|
userregfd[fd].next = userregfd_head;
|
userregfd[fd].next = userregfd_head;
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
MwUnregisterFdInput(HWND hwnd, int fd)
|
MwUnregisterFdInput(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (userregfd[fd].read == hwnd) {
|
if (userregfd[fd].read == hwnd) {
|
userregfd[fd].read = NULL;
|
userregfd[fd].read = NULL;
|
if (!userregfd[fd].write && !userregfd[fd].except) {
|
if (!userregfd[fd].write && !userregfd[fd].except) {
|
int *listfd = &userregfd_head;
|
int *listfd = &userregfd_head;
|
while (*listfd != -1) {
|
while (*listfd != -1) {
|
if (*listfd == fd) {
|
if (*listfd == fd) {
|
*listfd = userregfd[fd].next;
|
*listfd = userregfd[fd].next;
|
userregfd[fd].next = -1;
|
userregfd[fd].next = -1;
|
return;
|
return;
|
}
|
}
|
listfd = &userregfd[*listfd].next;
|
listfd = &userregfd[*listfd].next;
|
}
|
}
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
MwRegisterFdOutput(HWND hwnd, int fd)
|
MwRegisterFdOutput(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (!userregfd[fd].write) {
|
if (!userregfd[fd].write) {
|
userregfd[fd].write = hwnd;
|
userregfd[fd].write = hwnd;
|
if (userregfd[fd].next == -1 && !userregfd[fd].read && !userregfd[fd].except) {
|
if (userregfd[fd].next == -1 && !userregfd[fd].read && !userregfd[fd].except) {
|
userregfd[fd].next = userregfd_head;
|
userregfd[fd].next = userregfd_head;
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
MwUnregisterFdOutput(HWND hwnd, int fd)
|
MwUnregisterFdOutput(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (userregfd[fd].write == hwnd) {
|
if (userregfd[fd].write == hwnd) {
|
userregfd[fd].write = NULL;
|
userregfd[fd].write = NULL;
|
if (!userregfd[fd].read && !userregfd[fd].except) {
|
if (!userregfd[fd].read && !userregfd[fd].except) {
|
int *listfd = &userregfd_head;
|
int *listfd = &userregfd_head;
|
while (*listfd != -1) {
|
while (*listfd != -1) {
|
if (*listfd == fd) {
|
if (*listfd == fd) {
|
*listfd = userregfd[fd].next;
|
*listfd = userregfd[fd].next;
|
userregfd[fd].next = -1;
|
userregfd[fd].next = -1;
|
return;
|
return;
|
}
|
}
|
listfd = &userregfd[*listfd].next;
|
listfd = &userregfd[*listfd].next;
|
}
|
}
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
MwRegisterFdExcept(HWND hwnd, int fd)
|
MwRegisterFdExcept(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (!userregfd[fd].except) {
|
if (!userregfd[fd].except) {
|
userregfd[fd].except = hwnd;
|
userregfd[fd].except = hwnd;
|
if (userregfd[fd].next == -1 && !userregfd[fd].read && !userregfd[fd].write) {
|
if (userregfd[fd].next == -1 && !userregfd[fd].read && !userregfd[fd].write) {
|
userregfd[fd].next = userregfd_head;
|
userregfd[fd].next = userregfd_head;
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
MwUnregisterFdExcept(HWND hwnd, int fd)
|
MwUnregisterFdExcept(HWND hwnd, int fd)
|
{
|
{
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (fd < FD_SETSIZE && fd != mouse_fd && fd != keyb_fd) {
|
if (userregfd[fd].except == hwnd) {
|
if (userregfd[fd].except == hwnd) {
|
userregfd[fd].except = NULL;
|
userregfd[fd].except = NULL;
|
if (!userregfd[fd].read && !userregfd[fd].write) {
|
if (!userregfd[fd].read && !userregfd[fd].write) {
|
int *listfd = &userregfd_head;
|
int *listfd = &userregfd_head;
|
while (*listfd != -1) {
|
while (*listfd != -1) {
|
if (*listfd == fd) {
|
if (*listfd == fd) {
|
*listfd = userregfd[fd].next;
|
*listfd = userregfd[fd].next;
|
userregfd[fd].next = -1;
|
userregfd[fd].next = -1;
|
return;
|
return;
|
}
|
}
|
listfd = &userregfd[*listfd].next;
|
listfd = &userregfd[*listfd].next;
|
}
|
}
|
userregfd_head = fd;
|
userregfd_head = fd;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
#endif /* UNIX | DOS_DJGPP*/
|
#endif /* UNIX | DOS_DJGPP*/
|
|
|
#if MSDOS | _MINIX
|
#if MSDOS | _MINIX
|
void
|
void
|
MwSelect(void)
|
MwSelect(void)
|
{
|
{
|
/* If mouse data present, service it*/
|
/* If mouse data present, service it*/
|
if(mousedev.Poll())
|
if(mousedev.Poll())
|
while(MwCheckMouseEvent())
|
while(MwCheckMouseEvent())
|
continue;
|
continue;
|
|
|
/* If keyboard data present, service it*/
|
/* If keyboard data present, service it*/
|
if(kbddev.Poll())
|
if(kbddev.Poll())
|
while(MwCheckKeyboardEvent())
|
while(MwCheckKeyboardEvent())
|
continue;
|
continue;
|
|
|
MwHandleTimers();
|
MwHandleTimers();
|
}
|
}
|
#endif
|
#endif
|
|
|
#if UNIX && defined(HAVESELECT)
|
#if UNIX && defined(HAVESELECT)
|
#if ANIMATEPALETTE
|
#if ANIMATEPALETTE
|
static int fade = 0;
|
static int fade = 0;
|
#endif
|
#endif
|
|
|
void
|
void
|
MwSelect(void)
|
MwSelect(void)
|
{
|
{
|
fd_set rfds;
|
fd_set rfds;
|
fd_set wfds;
|
fd_set wfds;
|
fd_set efds;
|
fd_set efds;
|
int fd;
|
int fd;
|
int e;
|
int e;
|
int setsize = 0;
|
int setsize = 0;
|
UINT timeout;
|
UINT timeout;
|
struct timeval to;
|
struct timeval to;
|
|
|
/* perform pre-select duties, if any*/
|
/* perform pre-select duties, if any*/
|
if(scrdev.PreSelect)
|
if(scrdev.PreSelect)
|
scrdev.PreSelect(&scrdev);
|
scrdev.PreSelect(&scrdev);
|
|
|
/* Set up the FDs for use in the main select(): */
|
/* Set up the FDs for use in the main select(): */
|
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
FD_ZERO(&efds);
|
FD_ZERO(&efds);
|
|
|
if(mouse_fd >= 0) {
|
if(mouse_fd >= 0) {
|
FD_SET(mouse_fd, &rfds);
|
FD_SET(mouse_fd, &rfds);
|
if(mouse_fd > setsize)
|
if(mouse_fd > setsize)
|
setsize = mouse_fd;
|
setsize = mouse_fd;
|
}
|
}
|
if(keyb_fd >= 0) {
|
if(keyb_fd >= 0) {
|
FD_SET(keyb_fd, &rfds);
|
FD_SET(keyb_fd, &rfds);
|
if(keyb_fd > setsize)
|
if(keyb_fd > setsize)
|
setsize = keyb_fd;
|
setsize = keyb_fd;
|
}
|
}
|
|
|
/* handle registered file descriptors */
|
/* handle registered file descriptors */
|
fd = userregfd_head;
|
fd = userregfd_head;
|
while (fd != -1) {
|
while (fd != -1) {
|
if (userregfd[fd].read) FD_SET(fd, &rfds);
|
if (userregfd[fd].read) FD_SET(fd, &rfds);
|
if (userregfd[fd].write) FD_SET(fd, &wfds);
|
if (userregfd[fd].write) FD_SET(fd, &wfds);
|
if (userregfd[fd].except) FD_SET(fd, &efds);
|
if (userregfd[fd].except) FD_SET(fd, &efds);
|
if(fd > setsize) setsize = fd;
|
if(fd > setsize) setsize = fd;
|
fd = userregfd[fd].next;
|
fd = userregfd[fd].next;
|
}
|
}
|
|
|
++setsize;
|
++setsize;
|
|
|
/* Set up the timeout for the main select(). If
|
/* Set up the timeout for the main select(). If
|
* the mouse is captured we're probably moving a window,
|
* the mouse is captured we're probably moving a window,
|
* so poll quickly to allow other windows to repaint while
|
* so poll quickly to allow other windows to repaint while
|
* checking for more event input.
|
* checking for more event input.
|
*/
|
*/
|
if(dragwp)
|
if(dragwp)
|
timeout = to.tv_sec = to.tv_usec = 0L;
|
timeout = to.tv_sec = to.tv_usec = 0L;
|
else {
|
else {
|
timeout = MwGetNextTimeoutValue(); /* returns ms*/
|
timeout = MwGetNextTimeoutValue(); /* returns ms*/
|
#if ANIMATEPALETTE
|
#if ANIMATEPALETTE
|
if(fade < 100)
|
if(fade < 100)
|
timeout = 40;
|
timeout = 40;
|
#endif
|
#endif
|
if (!timeout) timeout = 10; /* temp kluge required for mdemo to run ok*/
|
if (!timeout) timeout = 10; /* temp kluge required for mdemo to run ok*/
|
GdGetNextTimeout(&to, timeout);
|
GdGetNextTimeout(&to, timeout);
|
}
|
}
|
|
|
/* Wait for some input on any of the fds in the set or a timeout: */
|
/* Wait for some input on any of the fds in the set or a timeout: */
|
if((e = select(setsize, &rfds, &wfds, &efds, &to)) > 0) {
|
if((e = select(setsize, &rfds, &wfds, &efds, &to)) > 0) {
|
|
|
/* If data is present on the mouse fd, service it: */
|
/* If data is present on the mouse fd, service it: */
|
if(mouse_fd >= 0 && FD_ISSET(mouse_fd, &rfds))
|
if(mouse_fd >= 0 && FD_ISSET(mouse_fd, &rfds))
|
while(MwCheckMouseEvent())
|
while(MwCheckMouseEvent())
|
continue;
|
continue;
|
|
|
/* If data is present on the keyboard fd, service it: */
|
/* If data is present on the keyboard fd, service it: */
|
if(keyb_fd >= 0 && FD_ISSET(keyb_fd, &rfds))
|
if(keyb_fd >= 0 && FD_ISSET(keyb_fd, &rfds))
|
while(MwCheckKeyboardEvent())
|
while(MwCheckKeyboardEvent())
|
continue;
|
continue;
|
|
|
/* If registered descriptor, handle it */
|
/* If registered descriptor, handle it */
|
fd = userregfd_head;
|
fd = userregfd_head;
|
while (fd != -1) {
|
while (fd != -1) {
|
if (userregfd[fd].read && FD_ISSET(fd, &rfds))
|
if (userregfd[fd].read && FD_ISSET(fd, &rfds))
|
PostMessage(userregfd[fd].read, WM_FDINPUT, fd, 0);
|
PostMessage(userregfd[fd].read, WM_FDINPUT, fd, 0);
|
if (userregfd[fd].write && FD_ISSET(fd, &wfds))
|
if (userregfd[fd].write && FD_ISSET(fd, &wfds))
|
PostMessage(userregfd[fd].write, WM_FDOUTPUT, fd, 0);
|
PostMessage(userregfd[fd].write, WM_FDOUTPUT, fd, 0);
|
if (userregfd[fd].except && FD_ISSET(fd, &efds))
|
if (userregfd[fd].except && FD_ISSET(fd, &efds))
|
PostMessage(userregfd[fd].except, WM_FDEXCEPT, fd, 0);
|
PostMessage(userregfd[fd].except, WM_FDEXCEPT, fd, 0);
|
fd = userregfd[fd].next;
|
fd = userregfd[fd].next;
|
}
|
}
|
}
|
}
|
else if(e == 0) {
|
else if(e == 0) {
|
/* timeout has occured*/
|
/* timeout has occured*/
|
if(GdTimeout() == FALSE)
|
if(GdTimeout() == FALSE)
|
return;
|
return;
|
#if ANIMATEPALETTE
|
#if ANIMATEPALETTE
|
if(fade <= 100) {
|
if(fade <= 100) {
|
setfadelevel(&scrdev, fade);
|
setfadelevel(&scrdev, fade);
|
fade += 5;
|
fade += 5;
|
}
|
}
|
#endif
|
#endif
|
MwHandleTimers();
|
MwHandleTimers();
|
} else
|
} else
|
if(errno != EINTR)
|
if(errno != EINTR)
|
EPRINTF("Select() call in main failed\n");
|
EPRINTF("Select() call in main failed\n");
|
}
|
}
|
#endif
|
#endif
|
|
|
#if VTSWITCH
|
#if VTSWITCH
|
static void
|
static void
|
CheckVtChange(void *arg)
|
CheckVtChange(void *arg)
|
{
|
{
|
if(MwCheckVtChange()) {
|
if(MwCheckVtChange()) {
|
#if ANIMATEPALETTE
|
#if ANIMATEPALETTE
|
fade = 0;
|
fade = 0;
|
#endif
|
#endif
|
MwRedrawScreen();
|
MwRedrawScreen();
|
}
|
}
|
GdAddTimer(50, CheckVtChange, NULL);
|
GdAddTimer(50, CheckVtChange, NULL);
|
}
|
}
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* Initialize the graphics and mouse devices at startup.
|
* Initialize the graphics and mouse devices at startup.
|
* Returns nonzero with a message printed if the initialization failed.
|
* Returns nonzero with a message printed if the initialization failed.
|
*/
|
*/
|
int
|
int
|
MwInitialize(void)
|
MwInitialize(void)
|
{
|
{
|
HWND wp; /* root window */
|
HWND wp; /* root window */
|
PSD psd;
|
PSD psd;
|
WNDCLASS wc;
|
WNDCLASS wc;
|
int fd;
|
int fd;
|
static MWCURSOR arrow = { /* default arrow cursor*/
|
static MWCURSOR arrow = { /* default arrow cursor*/
|
16, 16,
|
16, 16,
|
0, 0,
|
0, 0,
|
RGB(255, 255, 255), RGB(0, 0, 0),
|
RGB(255, 255, 255), RGB(0, 0, 0),
|
{ 0xe000, 0x9800, 0x8600, 0x4180,
|
{ 0xe000, 0x9800, 0x8600, 0x4180,
|
0x4060, 0x2018, 0x2004, 0x107c,
|
0x4060, 0x2018, 0x2004, 0x107c,
|
0x1020, 0x0910, 0x0988, 0x0544,
|
0x1020, 0x0910, 0x0988, 0x0544,
|
0x0522, 0x0211, 0x000a, 0x0004 },
|
0x0522, 0x0211, 0x000a, 0x0004 },
|
{ 0xe000, 0xf800, 0xfe00, 0x7f80,
|
{ 0xe000, 0xf800, 0xfe00, 0x7f80,
|
0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
|
0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
|
0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
|
0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
|
0x073e, 0x021f, 0x000e, 0x0004 }
|
0x073e, 0x021f, 0x000e, 0x0004 }
|
};
|
};
|
|
|
extern MWLISTHEAD mwClassHead;
|
extern MWLISTHEAD mwClassHead;
|
|
|
#if (UNIX | DOS_DJGPP) && !_MINIX
|
#if (UNIX | DOS_DJGPP) && !_MINIX
|
for (fd = 0; fd < FD_SETSIZE; fd++) {
|
for (fd = 0; fd < FD_SETSIZE; fd++) {
|
userregfd[fd].read = NULL;
|
userregfd[fd].read = NULL;
|
userregfd[fd].write = NULL;
|
userregfd[fd].write = NULL;
|
userregfd[fd].except = NULL;
|
userregfd[fd].except = NULL;
|
userregfd[fd].next = -1;
|
userregfd[fd].next = -1;
|
}
|
}
|
userregfd_head = -1;
|
userregfd_head = -1;
|
#endif
|
#endif
|
/* catch terminate signal to restore tty state*/
|
/* catch terminate signal to restore tty state*/
|
signal(SIGTERM, (void *)MwTerminate);
|
signal(SIGTERM, (void *)MwTerminate);
|
|
|
startTicks = GetTickCount();
|
startTicks = GetTickCount();
|
|
|
if ((keyb_fd = GdOpenKeyboard()) == -1) {
|
if ((keyb_fd = GdOpenKeyboard()) == -1) {
|
EPRINTF("Cannot initialise keyboard\n");
|
EPRINTF("Cannot initialise keyboard\n");
|
return -1;
|
return -1;
|
}
|
}
|
|
|
if ((psd = GdOpenScreen()) == NULL) {
|
if ((psd = GdOpenScreen()) == NULL) {
|
EPRINTF("Cannot initialise screen\n");
|
EPRINTF("Cannot initialise screen\n");
|
GdCloseKeyboard();
|
GdCloseKeyboard();
|
return -1;
|
return -1;
|
}
|
}
|
|
|
if ((mouse_fd = GdOpenMouse()) == -1) {
|
if ((mouse_fd = GdOpenMouse()) == -1) {
|
EPRINTF("Cannot initialise mouse\n");
|
EPRINTF("Cannot initialise mouse\n");
|
GdCloseScreen(psd);
|
GdCloseScreen(psd);
|
GdCloseKeyboard();
|
GdCloseKeyboard();
|
return -1;
|
return -1;
|
}
|
}
|
|
|
#if ANIMATEPALETTE
|
#if ANIMATEPALETTE
|
setfadelevel(psd, 0);
|
setfadelevel(psd, 0);
|
#endif
|
#endif
|
/*
|
/*
|
* Initialize the root window.
|
* Initialize the root window.
|
*/
|
*/
|
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
|
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
|
wc.lpfnWndProc = (WNDPROC)DefWindowProc;
|
wc.lpfnWndProc = (WNDPROC)DefWindowProc;
|
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.hInstance = 0;
|
wc.hInstance = 0;
|
wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/
|
wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/
|
wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
|
wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
|
wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
|
wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
|
wc.lpszMenuName = NULL;
|
wc.lpszMenuName = NULL;
|
wc.lpszClassName = "DeskTop";
|
wc.lpszClassName = "DeskTop";
|
RegisterClass( &wc);
|
RegisterClass( &wc);
|
|
|
wp = GdItemNew(struct hwnd);
|
wp = GdItemNew(struct hwnd);
|
if (!wp) {
|
if (!wp) {
|
EPRINTF("No memory for root window\n");
|
EPRINTF("No memory for root window\n");
|
GdCloseMouse();
|
GdCloseMouse();
|
GdCloseScreen(psd);
|
GdCloseScreen(psd);
|
GdCloseKeyboard();
|
GdCloseKeyboard();
|
return -1;
|
return -1;
|
}
|
}
|
/* remove the WS_CAPTION to have bare desktop window*/
|
/* remove the WS_CAPTION to have bare desktop window*/
|
/*wp->style = WS_CLIPCHILDREN | WS_CAPTION | WS_VISIBLE;*/
|
/*wp->style = WS_CLIPCHILDREN | WS_CAPTION | WS_VISIBLE;*/
|
wp->style = WS_CLIPCHILDREN | WS_VISIBLE;
|
wp->style = WS_CLIPCHILDREN | WS_VISIBLE;
|
wp->exstyle = 0;
|
wp->exstyle = 0;
|
wp->pClass = (PWNDCLASS)mwClassHead.head;
|
wp->pClass = (PWNDCLASS)mwClassHead.head;
|
wp->parent = NULL;
|
wp->parent = NULL;
|
wp->children = NULL;
|
wp->children = NULL;
|
wp->siblings = NULL;
|
wp->siblings = NULL;
|
wp->next = NULL;
|
wp->next = NULL;
|
SetRect(&wp->winrect, 0, 0, psd->xvirtres, psd->yvirtres);
|
SetRect(&wp->winrect, 0, 0, psd->xvirtres, psd->yvirtres);
|
MwCalcClientRect(wp);
|
MwCalcClientRect(wp);
|
wp->cursor = NULL;
|
wp->cursor = NULL;
|
wp->unmapcount = 0;
|
wp->unmapcount = 0;
|
wp->id = 0;
|
wp->id = 0;
|
strcpy(wp->szTitle, "Microwindows");
|
strcpy(wp->szTitle, "Microwindows");
|
wp->gotPaintMsg = PAINT_PAINTED;
|
wp->gotPaintMsg = PAINT_PAINTED;
|
#if UPDATEREGIONS
|
#if UPDATEREGIONS
|
wp->update = GdAllocRegion();
|
wp->update = GdAllocRegion();
|
#endif
|
#endif
|
|
|
listwp = wp;
|
listwp = wp;
|
rootwp = wp;
|
rootwp = wp;
|
focuswp = wp;
|
focuswp = wp;
|
mousewp = wp;
|
mousewp = wp;
|
|
|
/* schedule desktop window paint*/
|
/* schedule desktop window paint*/
|
InvalidateRect(rootwp, NULL, TRUE);
|
InvalidateRect(rootwp, NULL, TRUE);
|
|
|
#if VTSWITCH
|
#if VTSWITCH
|
MwInitVt();
|
MwInitVt();
|
/* Check for VT change every 50 ms: */
|
/* Check for VT change every 50 ms: */
|
GdAddTimer(50, CheckVtChange, NULL);
|
GdAddTimer(50, CheckVtChange, NULL);
|
#endif
|
#endif
|
|
|
/*
|
/*
|
* Initialize and position the default cursor.
|
* Initialize and position the default cursor.
|
*/
|
*/
|
curcursor = NULL;
|
curcursor = NULL;
|
cursorx = -1;
|
cursorx = -1;
|
cursory = -1;
|
cursory = -1;
|
GdShowCursor(psd);
|
GdShowCursor(psd);
|
MwMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2);
|
MwMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2);
|
MwSetCursor(rootwp, &arrow);
|
MwSetCursor(rootwp, &arrow);
|
|
|
/*
|
/*
|
* Finally tell the mouse driver some things.
|
* Finally tell the mouse driver some things.
|
*/
|
*/
|
GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1);
|
GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1);
|
GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2);
|
GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*
|
/*
|
* Here to close down the server.
|
* Here to close down the server.
|
*/
|
*/
|
void
|
void
|
MwTerminate(void)
|
MwTerminate(void)
|
{
|
{
|
GdCloseScreen(&scrdev);
|
GdCloseScreen(&scrdev);
|
GdCloseMouse();
|
GdCloseMouse();
|
GdCloseKeyboard();
|
GdCloseKeyboard();
|
#if VTSWITCH
|
#if VTSWITCH
|
MwRedrawVt(mwvterm);
|
MwRedrawVt(mwvterm);
|
MwExitVt();
|
MwExitVt();
|
#endif
|
#endif
|
exit(0);
|
exit(0);
|
}
|
}
|
|
|
/*
|
/*
|
* Return # milliseconds elapsed since start of Microwindows
|
* Return # milliseconds elapsed since start of Microwindows
|
* Granularity is 25 msec
|
* Granularity is 25 msec
|
*/
|
*/
|
DWORD WINAPI
|
DWORD WINAPI
|
GetTickCount(VOID)
|
GetTickCount(VOID)
|
{
|
{
|
#if MSDOS
|
#if MSDOS
|
#include <time.h>
|
#include <time.h>
|
return (DWORD)(clock() * 1000 / CLOCKS_PER_SEC);
|
return (DWORD)(clock() * 1000 / CLOCKS_PER_SEC);
|
#else
|
#else
|
#if _MINIX
|
#if _MINIX
|
struct tms t;
|
struct tms t;
|
|
|
return (DWORD)times(&t) * 16;
|
return (DWORD)times(&t) * 16;
|
#else
|
#else
|
#if UNIX
|
#if UNIX
|
struct timeval t;
|
struct timeval t;
|
|
|
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - startTicks;
|
return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - startTicks;
|
#else
|
#else
|
return 0L;
|
return 0L;
|
#endif
|
#endif
|
#endif
|
#endif
|
#endif
|
#endif
|
}
|
}
|
|
|
VOID WINAPI
|
VOID WINAPI
|
Sleep(DWORD dwMilliseconds)
|
Sleep(DWORD dwMilliseconds)
|
{
|
{
|
int i, j, k;
|
int i, j, k;
|
const int loops_per_ms = 20000;
|
const int loops_per_ms = 20000;
|
|
|
/* FIXME this is not calibrated */
|
/* FIXME this is not calibrated */
|
for(i=0; i < dwMilliseconds; i++)
|
for(i=0; i < dwMilliseconds; i++)
|
for(j=0; j < loops_per_ms; j++)
|
for(j=0; j < loops_per_ms; j++)
|
k = i * j;
|
k = i * j;
|
}
|
}
|
|
|