commit 7d65dbf65e81726e842ab1860c61d8eb09fb9dd8
parent 05d0cbd009a346b7112cd5c71574d2bbd26ebf0d
Author: Michael Savage <mikejsavage@gmail.com>
Date: Fri, 12 Jul 2013 21:00:42 +0100
Add mud.urgent
Diffstat:
4 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/main.lua b/main.lua
@@ -18,7 +18,7 @@ require( "connect" ).init( handlers.data )
local xFD, handleXEvents,
printMain, newlineMain, drawMain,
printChat, newlineChat, drawChat,
- setHandlers = ...
+ setHandlers, urgent = ...
mud.printMain = printMain
mud.newlineMain = newlineMain
@@ -28,6 +28,8 @@ mud.printChat = printChat
mud.newlineChat = newlineChat
mud.drawChat = drawChat
+mud.urgent = urgent
+
setHandlers( handlers.input, handlers.macro, handlers.close )
local loop = ev.Loop.default
diff --git a/src/common.h b/src/common.h
@@ -23,6 +23,8 @@ struct
int width;
int height;
+
+ int hasFocus;
} UI;
typedef struct
diff --git a/src/script.c b/src/script.c
@@ -5,6 +5,8 @@
#include <lualib.h>
#include <lauxlib.h>
+#include <X11/Xutil.h>
+
#include "common.h"
#include "ui.h"
@@ -132,6 +134,20 @@ static int mud_setHandlers( lua_State* L )
return 0;
}
+static int mud_urgent( lua_State* L )
+{
+ PRETEND_TO_USE( L );
+
+ if( !UI.hasFocus ) {
+ XWMHints* hints = XGetWMHints( UI.display, UI.window );
+ hints->flags |= XUrgencyHint;
+ XSetWMHints( UI.display, UI.window, hints );
+ XFree( hints );
+ }
+
+ return 0;
+}
+
void script_init()
{
mud_handleXEvents( NULL );
@@ -163,7 +179,9 @@ void script_init()
lua_pushcfunction( L, mud_setHandlers );
- if( lua_pcall( L, 9, 0, -11 ) )
+ lua_pushcfunction( L, mud_urgent );
+
+ if( lua_pcall( L, 10, 0, -11 ) )
{
printf( "Error running main.lua: %s\n", lua_tostring( L, -1 ) );
diff --git a/src/ui.c b/src/ui.c
@@ -233,6 +233,24 @@ void eventKeyPress( XEvent* event )
#undef ADD_MACRO
}
+void eventFocusOut( XEvent* event ) {
+ PRETEND_TO_USE( event );
+
+ UI.hasFocus = 0;
+}
+
+void eventFocusIn( XEvent* event )
+{
+ PRETEND_TO_USE( event );
+
+ UI.hasFocus = 1;
+
+ XWMHints* hints = XGetWMHints( UI.display, UI.window );
+ hints->flags &= ~XUrgencyHint;
+ XSetWMHints( UI.display, UI.window, hints );
+ XFree( hints );
+}
+
void ( *EventHandler[ LASTEvent ] ) ( XEvent* ) =
{
[ ButtonPress ] = eventButtonPress,
@@ -241,6 +259,8 @@ void ( *EventHandler[ LASTEvent ] ) ( XEvent* ) =
[ ConfigureNotify ] = eventResize,
[ Expose ] = eventExpose,
[ KeyPress ] = eventKeyPress,
+ [ FocusOut ] = eventFocusOut,
+ [ FocusIn ] = eventFocusIn,
};
void ui_handleXEvents()
@@ -352,13 +372,17 @@ void ui_init()
XSetWindowAttributes attr =
{
.background_pixel = Style.bg,
- .event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask,
+ .event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask,
.colormap = UI.colorMap,
};
UI.window = XCreateWindow( UI.display, root, 0, 0, 800, 600, 0, depth, InputOutput, visual, CWBackPixel | CWEventMask | CWColormap, &attr );
UI.gc = XCreateGC( UI.display, UI.window, 0, NULL );
+ XWMHints* hints = XAllocWMHints();
+ XSetWMHints( UI.display, UI.window, hints );
+ XFree( hints );
+
Cursor cursor = XCreateFontCursor( UI.display, XC_xterm );
XDefineCursor( UI.display, UI.window, cursor );
XRecolorCursor( UI.display, cursor, &Style.xFG, &Style.xBG );