if( Window->Flags & WINFLAG_MAXIMIZED )
return ;
- _SysDebug("BorderL = %i", ciSideBorderWidth);
-
Window->BorderB = ciBottomBorderWidth;
Window->BorderR = ciSideBorderWidth;
Window->BorderL = ciSideBorderWidth;
--- /dev/null
+/*
+ * Acess2 GUI (AxWin) Version 3
+ * - By John Hodge (thePowersGang)
+ *
+ * wm_input.h
+ * - Window Manager Input
+ */
+#ifndef _WM_INPUT_H_
+#define _WM_INPUT_H_
+
+extern void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY);
+extern void WM_Input_MouseButton(int X, int Y, int Button, int Pressed);
+extern void WM_Input_KeyDown(uint32_t Character, uint32_t Scancode);
+extern void WM_Input_KeyFire(uint32_t Character, uint32_t Scancode);
+extern void WM_Input_KeyUp (uint32_t Character, uint32_t Scancode);
+
+#endif
+
uint8_t bPressed;
};
+struct sWndMsg_KeyAction
+{
+ uint32_t KeySym;
+ uint32_t UCS32;
+};
+
#endif
*/
#include <common.h>
#include <acess/sys.h>
+#include <wm_input.h>
// TODO: Move out to a common header
typedef struct
// === IMPORTS ===
extern void Video_SetCursorPos(short X, short Y);
-extern void WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY);
-extern void WM_Input_MouseButton(int X, int Y, int Button, int Pressed);
const char *gsMouseDevice;
extern int giTerminalFD;
extern int giScreenWidth;
if(FD_ISSET(giTerminalFD, set))
{
uint32_t codepoint;
+ static uint32_t scancode;
+ #define KEY_CODEPOINT_MASK 0x3FFFFFFF
+
if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
{
// oops, error
}
+
+ switch(codepoint & 0xC0000000)
+ {
+ case 0x00000000: // Key pressed
+ WM_Input_KeyDown(codepoint & KEY_CODEPOINT_MASK, scancode);
+ case 0x40000000: // Key refire
+ WM_Input_KeyFire(codepoint & KEY_CODEPOINT_MASK, scancode);
+ scancode = 0;
+ break;
+ case 0x80000000: // Key release
+ WM_Input_KeyUp(codepoint & KEY_CODEPOINT_MASK, scancode);
+ scancode = 0;
+ break;
+ case 0xC0000000: // Raw scancode
+ scancode = codepoint & KEY_CODEPOINT_MASK;
+ break;
+ }
+
// TODO: pass on to message handler
_SysDebug("Keypress 0x%x", codepoint);
}
}
gaWM_WidgetTypes[Type] = Ptr;
- _SysDebug("Registered type %i to %p", Type, Ptr);
}
tWindow *Renderer_Widget_Create(int Flags)
info = ret->RendererInfo;
info->TableSize = eletable_size;
+ info->FocusedElement = &info->RootElement;
info->RootElement.Window = ret;
info->RootElement.ID = -1;
info->RootElement.BackgroundColour = 0xCCCCCC;
Widget_UpdateMinDims(parent);
}
+void Widget_SetFocus(tWidgetWin *Info, tElement *Ele)
+{
+ // TODO: Callbacks
+
+ Info->FocusedElement = Ele;
+}
+
void Widget_SetFlags(tWidgetWin *Info, int Len, const tWidgetMsg_SetFlags *Msg)
{
tElement *ele;
int Renderer_Widget_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data)
{
tWidgetWin *info = Target->RendererInfo;
+ tElement *ele;
switch(Msg)
{
case WNDMSG_RESIZE: {
case WNDMSG_MOUSEBTN: {
const struct sWndMsg_MouseButton *msg = Data;
tWidgetMsg_MouseBtn client_msg;
- tElement *ele;
int x, y;
int rv;
client_msg.bPressed = msg->bPressed;
ele = Widget_GetElementByPos(info, x, y);
+ Widget_SetFocus(info, ele);
// Send event to all elements from `ele` upwards
for( ; ele; ele = ele->Parent )
{
}
return 0; }
+ case WNDMSG_KEYDOWN: {
+ const struct sWndMsg_KeyAction *msg = Data;
+ if(Len < sizeof(*msg)) return -1;
+
+ if(!info->FocusedElement) return 0;
+ ele = info->FocusedElement;
+
+ if(gaWM_WidgetTypes[ele->Type]->KeyDown)
+ gaWM_WidgetTypes[ele->Type]->KeyDown(ele, msg->KeySym, msg->UCS32);
+ else
+ {
+ // TODO: Pass to user
+ }
+
+ return 0; }
+
+ case WNDMSG_KEYFIRE: {
+ const struct sWndMsg_KeyAction *msg = Data;
+ if(Len < sizeof(*msg)) return -1;
+
+ if(!info->FocusedElement) return 0;
+ ele = info->FocusedElement;
+
+ if(gaWM_WidgetTypes[ele->Type]->KeyFire)
+ gaWM_WidgetTypes[ele->Type]->KeyFire(ele, msg->KeySym, msg->UCS32);
+ else
+ {
+ // TODO: Pass the buck
+ }
+ return 0; }
+
+ case WNDMSG_KEYUP: {
+ const struct sWndMsg_KeyAction *msg = Data;
+ if(Len < sizeof(*msg)) return -1;
+
+ if(!info->FocusedElement) return 0;
+ ele = info->FocusedElement;
+
+ if(gaWM_WidgetTypes[ele->Type]->KeyUp)
+ gaWM_WidgetTypes[ele->Type]->KeyUp(ele, msg->KeySym);
+ else
+ {
+ // TODO: Pass the buck
+ }
+ return 0; }
+
// New Widget
case MSG_WIDGET_CREATE:
Widget_NewWidget(info, Len, Data);
return 0;
+ // Delete a widget
case MSG_WIDGET_DELETE:
_SysDebug("TODO: Implement MSG_WIDGET_DELETE");
return 0;
+ // Set focused widget
+ case MSG_WIDGET_SETFOCUS: {
+ tElement *ele;
+ const tWidgetMsg_SetFocus *msg = Data;
+ if(Len < sizeof(*msg)) return -1;
+
+ ele = Widget_GetElementById(info, msg->WidgetID);
+ Widget_SetFocus(info, ele);
+ return 0; }
+
// Set Flags
case MSG_WIDGET_SETFLAGS:
Widget_SetFlags(info, Len, Data);
WM_Render_SetTextCursor(Window,
Element->CachedX+2+info->CursorXOfs,
Element->CachedY+2,
- Element->CachedW-4, 1,
+ 1, Element->CachedH-4,
TEXTINPUT_TEXT
);
}
// No need to explicitly update parent min dims, as the AddElement routine does that
}
+int Widget_TextInput_KeyFire(tElement *Ele, int KeySym, int Character)
+{
+ _SysDebug("Key 0x%x fired ('%c')", Character, Character);
+ return 0;
+}
+
DEFWIDGETTYPE(ELETYPE_TEXTINPUT,
WIDGETTYPE_FLAG_NOCHILDREN,
.Render = Widget_TextInput_Render,
- .Init = Widget_TextInput_Init
+ .Init = Widget_TextInput_Init,
+ .KeyFire = Widget_TextInput_KeyFire
);
dest = gpScreenBuffer + Y * giScreenWidth + X;
while(H --)
{
- for( i = W; W --; dest ++) *dest = Colour;
+ for( i = W; i --; dest ++ ) *dest = Colour;
dest += giScreenWidth - W;
}
}
// === IMPORTS ===
extern tWindow *gpWM_RootWindow;
+extern tWindow *gpWM_FocusedWindow;
// === GLOBALS ===
//! Window in which the mouse button was originally pressed
WM_Input_int_SendBtnMsg(win, X, Y, ButtonIndex, Pressed);
}
+void WM_Input_KeyDown(uint32_t Character, uint32_t Scancode)
+{
+ struct sWndMsg_KeyAction msg;
+ msg.KeySym = Scancode;
+ msg.UCS32 = Character;
+ WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYDOWN, sizeof(msg), &msg);
+}
+
+void WM_Input_KeyFire(uint32_t Character, uint32_t Scancode)
+{
+ struct sWndMsg_KeyAction msg;
+ msg.KeySym = Scancode;
+ msg.UCS32 = Character;
+ WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYFIRE, sizeof(msg), &msg);
+}
+
+void WM_Input_KeyUp(uint32_t Character, uint32_t Scancode)
+{
+ struct sWndMsg_KeyAction msg;
+ msg.KeySym = Scancode;
+ msg.UCS32 = Character;
+ WM_SendMessage(NULL, gpWM_FocusedWindow, WNDMSG_KEYUP, sizeof(msg), &msg);
+}
+
// Control (Client->Server) messages
MSG_WIDGET_CREATE = 0x1000,
MSG_WIDGET_DELETE,
+ MSG_WIDGET_SETFOCUS,
MSG_WIDGET_SETFLAGS,
MSG_WIDGET_SETSIZE,
MSG_WIDGET_SETTEXT,
uint32_t WidgetID;
} tWidgetMsg_Delete;
+typedef struct
+{
+ uint32_t WidgetID;
+} tWidgetMsg_SetFocus;
+
typedef struct
{
uint32_t WidgetID;