OSX Xboard 4.7.2 .app

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Haha I can learn!

Code: Select all

if(!msg) break;
      if(!strcmp(msg, "Quit ")) continue;
      if(!strcmp(msg, "----") && !strcmp(mb[i+1].string, "Quit ")) continue;
     if(!strcmp(msg, "----") && !strcmp(mb[i+1].string, "About XBoard")) continue;
	  if(strcmp(msg, "----")) { //
Worked just fine as the About Xboard was moved after creation[/code]

I should take a look at
gtkosx_application_set_use_quartz_accelerators ()
so I wouldn't have to edit the table.
It says it should be on by default but when I tried without it evreything in the menu was still ctrl. So I may have to add it. It says its a boolean value though so shouldn't be hard.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

I tried

Code: Select all

	    {
      		GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
      		extern MenuItem helpMenu[]; 
      		gtk_widget_hide (menuBar);
            gtkosx_application_set_use_quartz_accelerators (theApp, TRUE);
      		gtkosx_application_set_menu_bar(theApp, GTK_MENU_SHELL(menuBar));
      		gtkosx_application_insert_app_menu_item(theApp, GTK_MENU_ITEM(helpMenu[8].handle), 0);
            gtkosx_application_ready(theApp);
  	   } 
but all the ctrls were still ctrl in the menu. I must be doing something wrong or there is some other element stopping me.

I should also add that even though it works, i get this warning at runtime. is there something with syntax it's not liking?

Code: Select all

/opt/local/include/gtkmacintegration/gtkosxapplication.h:78:6: note: expected 'struct GtkWidget *' but argument is of type 'struct GtkMenuItem *'
 void gtkosx_application_insert_app_menu_item (GtkosxApplication *self,
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

sorry,
That wasn't the warning. I have too many windows open, This was. It's probably a result of the commenting out, in which case, no matter.

Code: Select all

(Xboard-bin:68007): Gtk-CRITICAL **: void gtk_table_attach(GtkTable *, GtkWidget *, guint, guint, guint, guint, GtkAttachOptions, GtkAttachOptions, guint, guint): assertion 'child->parent == NULL' failed
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

JoshPettus wrote:Haha I can learn!

Code: Select all

if(!msg) break;
      if(!strcmp(msg, "Quit ")) continue;
      if(!strcmp(msg, "----") && !strcmp(mb[i+1].string, "Quit ")) continue;
     if(!strcmp(msg, "----") && !strcmp(mb[i+1].string, "About XBoard")) continue;
	  if(strcmp(msg, "----")) { //
Well done!

When did the run-time warning first appear? The problem is that this message is very non-informative, as gtk_table_attach is used all over the place, for putting the various elements of the window in their proper place. The 'child->parent == NULL' is also rather cryptic, although it suggests we a putting something into a table that was already there, or in some other table.

The table_attach line that was commented out cannot possibly be responsible for this message, precisely because it was commented out.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Oh i found the issue. I had accidentally uncommitted the table attach line above it at one point. Oops :) warning gone.

Any ideas about the set quartz accelerator thing? or should I leave the table as I have it now with replacing evrey instance of <Ctrl> with <Meta> at the moment? It would be nice not to touch the menu.c but I can't figure it out.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

Well, I did not write the accelerator code myself (Arun did). But from what I see it takes the text strings included in the menu tables in menus.c, uses gtk_accelerator_parse() to convert these to some key-stroke ID, and then use gtk_widget_add_accelerator() to associate it with a menu item.

The menu item thus never gets to see the actual text string describing the key stroke. The text appearing next to the menu item must be generated by GTK itself, based on the key-stroke ID (key number + modifiers). I would expect the GTK-OSX routines to re-interpret these key IDs in their own way, and generate the corresponding text. If it doesn't I really have no idea why that would be.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

I see so there isn't much I can do about that, at least not with a simple line. Oh well.

Well here is the patch file of everything that I modified in the source code

https://dl.dropboxusercontent.com/u/504 ... dOSX.patch

and this little patch to help it compile on OS10.6, since 10.6 doesn't have the strndup function. It was a hack I found on google to define it for the compiler

https://dl.dropboxusercontent.com/u/504 ... 6fix.patch
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

I wonder if we don't expect this quartz_accelerators thing to do more than they actually promise. It says it would replace stock accelerators like Ctrl-O to the OSX equivalent. Not that they would change every Ctrl int Meta.

But we can do the latter in the (somewhat) hard way without touching menus.c, by inserting code in CreateMenuPopup() to do the replacement for us:

Code: Select all

  if&#40;mb&#91;i&#93;.accel&#41; &#123;
    guint accelerator_key;
    GdkModifierType accelerator_mods;
    char *p = strstr&#40;mb&#91;i&#93;.accel, "Ctrl"); // ADD

    if&#40;p&#41; &#123; // ADD this and next 2
      p&#91;0&#93; = 'M'; p&#91;1&#93; = 'e'; p&#91;2&#93; = 't'; p&#91;3&#93; = 'a';
    &#125;
    gtk_accelerator_parse&#40;mb&#91;i&#93;.accel, &accelerator_key, &accelerator_mods&#41;;
    gtk_widget_add_accelerator &#40;GTK_WIDGET&#40;entry&#41;, "activate",GtkAccelerators,
                accelerator_key, accelerator_mods, GTK_ACCEL_VISIBLE&#41;;
  &#125;;
(This patch makes essential use of the fact that Ctrl and Meta are both 4 letters, so that any Ctrl that is detected in the accelerator name can be over-written in-place by Meta before offering it to GTK for parsing. There might be a smarter way to do this, which is detect the use of Ctrl only after parsing of the text, where presumably its use would be indicated by some bits in 'accelerator_mods', and then clear those bits, and set the bits corresponding to the Meta modifier instead. But that would require us to figure out how the modifier keys are encoded in the accelerator_mods. Advantage is that it would also work for replacing modifier keys by keys with names of unequal length.)

[Edit] This table could be helpful.

Code: Select all

typedef enum &#123;
  GDK_SHIFT_MASK    = 1 << 0,
  GDK_LOCK_MASK	    = 1 << 1,
  GDK_CONTROL_MASK  = 1 << 2,
  GDK_MOD1_MASK	    = 1 << 3,
  GDK_MOD2_MASK	    = 1 << 4,
  GDK_MOD3_MASK	    = 1 << 5,
  GDK_MOD4_MASK	    = 1 << 6,
  GDK_MOD5_MASK	    = 1 << 7,
  GDK_BUTTON1_MASK  = 1 << 8,
  GDK_BUTTON2_MASK  = 1 << 9,
  GDK_BUTTON3_MASK  = 1 << 10,
  GDK_BUTTON4_MASK  = 1 << 11,
  GDK_BUTTON5_MASK  = 1 << 12,

  /* The next few modifiers are used by XKB, so we skip to the end.
   * Bits 15 - 25 are currently unused. Bit 29 is used internally.
   */
  
  GDK_SUPER_MASK    = 1 << 26,
  GDK_HYPER_MASK    = 1 << 27,
  GDK_META_MASK     = 1 << 28,
  
  GDK_RELEASE_MASK  = 1 << 30,

  GDK_MODIFIER_MASK = 0x5c001fff
&#125; GdkModifierType;
Using that, we would just have to add after the accelerator_parse:

Code: Select all

    gtk_accelerator_parse&#40;mb&#91;i&#93;.accel, &accelerator_key, &accelerator_mods&#41;;
    if&#40;accelerator_mods & GDK_CONTROL_MASK&#41; &#123;
      accelerator_mods &= ~GDK_CONTROL_MASK; // clear Ctrl flag
      accelerator_mods |= GDK_META_MASK; // set Meta flag
    &#125;
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Ah you're probably right.

I gave your patch a try, it compiles. but when I try to run the executable i get a ctd with nothing but
bus error 10
if that means anything to you.

It sounds like neat patch though and would be a lot better then changing the menu.c

[edit]
oh didn't see your edit! :)

[edit2]
Much better! works like a charm. Lot shorter too!
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Here is a new patch with your fix

https://dl.dropboxusercontent.com/u/504 ... dOSX.patch

I want to thank-you for all your help. Everything looks great! :)