Add task-bar icon
[xboard.git] / xboard.c
index 5c42dba..0ac3a44 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -197,6 +197,7 @@ char *FindFont P((char *pattern, int targetPxlSize));
 #endif
 void DelayedDrag P((void));
 void ICSInputBoxPopUp P((void));
+gboolean KeyPressProc P((GtkWindow *window, GdkEventKey *eventkey, gpointer data));
 #ifdef TODO_GTK
 static void MoveTypeInProc P((Widget widget, caddr_t unused, XEvent *event));
 void HandlePV P((Widget w, XEvent * event,
@@ -253,6 +254,11 @@ char *layoutName;
 
 char installDir[] = "."; // [HGM] UCI: needed for UCI; probably needs run-time initializtion
 
+/* pixbufs */
+static GdkPixbuf       *mainwindowIcon=NULL;
+static GdkPixbuf       *WhiteIcon=NULL;
+static GdkPixbuf       *BlackIcon=NULL;
+
 typedef unsigned int BoardSize;
 BoardSize boardSize;
 Boolean chessProgram;
@@ -1297,18 +1303,13 @@ main (int argc, char **argv)
     InitMenuMarkers();
 
     /*
-     * Create an icon.
+     * Create an icon. (Use two icons, to indicate whther it is white's or black's turn.)
      */
-#ifdef TODO_GTK
-    ReadBitmap(&wIconPixmap, "icon_white.bm",
-              icon_white_bits, icon_white_width, icon_white_height);
-    ReadBitmap(&bIconPixmap, "icon_black.bm",
-              icon_black_bits, icon_black_width, icon_black_height);
-    iconPixmap = wIconPixmap;
-    i = 0;
-    XtSetArg(args[i], XtNiconPixmap, iconPixmap);  i++;
-    XtSetValues(shellWidget, args, i);
-#endif
+    WhiteIcon  = gdk_pixbuf_new_from_file(SVGDIR "/icon_white.svg", NULL);
+    BlackIcon  = gdk_pixbuf_new_from_file(SVGDIR "/icon_black.svg", NULL);
+    mainwindowIcon = WhiteIcon;
+    gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
+
 
     /*
      * Create a cursor for the board widget.
@@ -1359,6 +1360,7 @@ main (int argc, char **argv)
     XtAddEventHandler(shellWidget, StructureNotifyMask, False,
                      (XtEventHandler) EventProc, NULL);
 #endif
+    g_signal_connect(shells[BoardWindow], "key-press-event", G_CALLBACK(KeyPressProc), NULL);
 
     /* [AS] Restore layout */
     if( wpMoveHistory.visible ) {
@@ -1633,7 +1635,6 @@ SetMenuEnables (Enables *enab)
   }
 }
 
-#ifdef TODO_GTK
 gboolean KeyPressProc(window, eventkey, data)
      GtkWindow *window;
      GdkEventKey  *eventkey;
@@ -1642,25 +1643,7 @@ gboolean KeyPressProc(window, eventkey, data)
 
     MoveTypeInProc(eventkey); // pop up for typed in moves
 
-    // handle shift+<number> cases
-    if (eventkey->state & GDK_SHIFT_MASK) {
-        guint keyval;
-
-        gdk_keymap_translate_keyboard_state(NULL, eventkey->hardware_keycode,
-                                           0, eventkey->group,
-                                           &keyval, NULL, NULL, NULL);
-        switch(keyval) {
-            case GDK_1:
-                AskQuestionEvent("Direct command", "Send to chess program:", "", "1");
-                break;
-            case GDK_2:
-                AskQuestionEvent("Direct command", "Send to second chess program:", "", "2");
-                break;
-            default:
-                break;
-        }
-    }
-
+#ifdef TODO_GTK
     /* check for other key values */
     switch(eventkey->keyval) {
         case GDK_question:
@@ -1669,8 +1652,10 @@ gboolean KeyPressProc(window, eventkey, data)
         default:
          break;
     }
+#endif
     return False;
 }
+#ifdef TODO_GTK
 void
 KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 {   // [HGM] new method of key binding: specify MenuItem(FlipView) in stead of FlipViewProc in translation string
@@ -2255,22 +2240,16 @@ DisplayTimerLabel (Option *opt, char *color, long timer, int highlight)
     g_free(markup);
 }
 
-#ifdef TODO_GTK
-static Pixmap *clockIcons[] = { &wIconPixmap, &bIconPixmap };
-#endif
+static GdkPixbuf **clockIcons[] = { &WhiteIcon, &BlackIcon };
 
 void
 SetClockIcon (int color)
 {
-#ifdef TODO_GTK
-    Arg args[16];
-    Pixmap pm = *clockIcons[color];
-    if (iconPixmap != pm) {
-       iconPixmap = pm;
-       XtSetArg(args[0], XtNiconPixmap, iconPixmap);
-       XtSetValues(shellWidget, args, 1);
+    GdkPixbuf *pm = *clockIcons[color];
+    if (mainwindowIcon != pm) {
+        mainwindowIcon = pm;
+       gtk_window_set_icon(GTK_WINDOW(shellWidget), mainwindowIcon);
     }
-#endif
 }
 
 #define INPUT_SOURCE_BUF_SIZE 8192