Fixes (mostly from Colin Watson, a couple redone by me) to make Unix
[u/mdw/putty] / unix / gtkwin.c
index 393d98f..be8b2c3 100644 (file)
 #define CAT(x,y) CAT2(x,y)
 #define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)}
 
+#if GTK_CHECK_VERSION(2,0,0)
+ASSERT(sizeof(long) <= sizeof(gsize));
+#define LONG_TO_GPOINTER(l) GSIZE_TO_POINTER(l)
+#define GPOINTER_TO_LONG(p) GPOINTER_TO_SIZE(p)
+#else /* Gtk 1.2 */
+ASSERT(sizeof(long) <= sizeof(gpointer));
+#define LONG_TO_GPOINTER(l) ((gpointer)(long)(l))
+#define GPOINTER_TO_LONG(p) ((long)(p))
+#endif
+
 /* Colours come in two flavours: configurable, and xterm-extended. */
 #define NCFGCOLOURS (lenof(((Config *)0)->colours))
 #define NEXTCOLOURS 240 /* 216 colour-cube plus 24 shades of grey */
@@ -1052,19 +1062,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
              case GDK_Begin: case GDK_KP_Begin: xkey = 'G'; break;
            }
            if (xkey) {
-               /*
-                * The arrow keys normally do ESC [ A and so on. In
-                * app cursor keys mode they do ESC O A instead.
-                * Ctrl toggles the two modes.
-                */
-               if (inst->term->vt52_mode) {
-                   end = 1 + sprintf(output+1, "\033%c", xkey);
-               } else if (!inst->term->app_cursor_keys ^
-                          !(event->state & GDK_CONTROL_MASK)) {
-                   end = 1 + sprintf(output+1, "\033O%c", xkey);
-               } else {                    
-                   end = 1 + sprintf(output+1, "\033[%c", xkey);
-               }
+               end = 1 + format_arrow_key(output+1, inst->term, xkey,
+                                          event->state & GDK_CONTROL_MASK);
                use_ucsoutput = FALSE;
                goto done;
            }
@@ -1291,14 +1290,14 @@ void notify_remote_exit(void *frontend)
 
 static gint timer_trigger(gpointer data)
 {
-    long now = GPOINTER_TO_SIZE(data);
+    long now = GPOINTER_TO_LONG(data);
     long next;
     long ticks;
 
     if (run_timers(now, &next)) {
        ticks = next - GETTICKCOUNT();
        timer_id = gtk_timeout_add(ticks > 0 ? ticks : 1, timer_trigger,
-                                  GSIZE_TO_POINTER(next));
+                                  LONG_TO_GPOINTER(next));
     }
 
     /*
@@ -1320,7 +1319,7 @@ void timer_change_notify(long next)
        ticks = 1;                     /* just in case */
 
     timer_id = gtk_timeout_add(ticks, timer_trigger,
-                              GSIZE_TO_POINTER(next));
+                              LONG_TO_GPOINTER(next));
 }
 
 void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
@@ -3431,6 +3430,9 @@ int pt_main(int argc, char **argv)
     init_cutbuffers();
 
     inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    if (inst->cfg.winclass[0])
+        gtk_window_set_wmclass(GTK_WINDOW(inst->window),
+                               inst->cfg.winclass, inst->cfg.winclass);
 
     /*
      * Set up the colour map.
@@ -3538,15 +3540,29 @@ int pt_main(int argc, char **argv)
 
        inst->menu = gtk_menu_new();
 
-#define MKMENUITEM(title, func) do { \
-    menuitem = title ? gtk_menu_item_new_with_label(title) : \
-    gtk_menu_item_new(); \
-    gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \
-    gtk_widget_show(menuitem); \
-    if (func != NULL) \
-       gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \
-                              GTK_SIGNAL_FUNC(func), inst); \
-} while (0)
+#define MKMENUITEM(title, func) do                                      \
+        {                                                               \
+            menuitem = gtk_menu_item_new_with_label(title);             \
+            gtk_container_add(GTK_CONTAINER(inst->menu), menuitem);     \
+            gtk_widget_show(menuitem);                                  \
+            gtk_signal_connect(GTK_OBJECT(menuitem), "activate",        \
+                               GTK_SIGNAL_FUNC(func), inst);            \
+        } while (0)
+
+#define MKSUBMENU(title) do                                             \
+        {                                                               \
+            menuitem = gtk_menu_item_new_with_label(title);             \
+            gtk_container_add(GTK_CONTAINER(inst->menu), menuitem);     \
+            gtk_widget_show(menuitem);                                  \
+        } while (0)
+
+#define MKSEP() do                                                      \
+        {                                                               \
+            menuitem = gtk_menu_item_new();                             \
+            gtk_container_add(GTK_CONTAINER(inst->menu), menuitem);     \
+            gtk_widget_show(menuitem);                                  \
+        } while (0)
+
        if (new_session)
            MKMENUITEM("New Session...", new_session_menuitem);
         MKMENUITEM("Restart Session", restart_session_menuitem);
@@ -3561,27 +3577,29 @@ int pt_main(int argc, char **argv)
            gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),
                                      inst->sessionsmenu);
        }
-       MKMENUITEM(NULL, NULL);
+       MKSEP();
         MKMENUITEM("Change Settings...", change_settings_menuitem);
-       MKMENUITEM(NULL, NULL);
+       MKSEP();
        if (use_event_log)
            MKMENUITEM("Event Log", event_log_menuitem);
-       MKMENUITEM("Special Commands", NULL);
+       MKSUBMENU("Special Commands");
        inst->specialsmenu = gtk_menu_new();
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), inst->specialsmenu);
        inst->specialsitem1 = menuitem;
-       MKMENUITEM(NULL, NULL);
+       MKSEP();
        inst->specialsitem2 = menuitem;
        gtk_widget_hide(inst->specialsitem1);
        gtk_widget_hide(inst->specialsitem2);
        MKMENUITEM("Clear Scrollback", clear_scrollback_menuitem);
        MKMENUITEM("Reset Terminal", reset_terminal_menuitem);
        MKMENUITEM("Copy All", copy_all_menuitem);
-       MKMENUITEM(NULL, NULL);
+       MKSEP();
        s = dupcat("About ", appname, NULL);
        MKMENUITEM(s, about_menuitem);
        sfree(s);
 #undef MKMENUITEM
+#undef MKSUBMENU
+#undef MKSEP
     }
 
     inst->textcursor = make_mouse_ptr(inst, GDK_XTERM);