From bf212ac737d114d639457802ce8b1363a465c7a3 Mon Sep 17 00:00:00 2001
From: longcheng <longcheng@kylinos.com.cn>
Date: Thu, 24 Mar 2022 18:58:13 +0800
Subject: [PATCH 2/5] feature[menu] : pop up start menu when press super key

---
 po/zh_CN.po                     |  3 +++
 src/50-marco-desktop-key.xml.in |  2 ++
 src/core/atomnames.h            |  1 +
 src/core/keybindings.c          | 48 +++++++++++++++++++++++++++++++++
 src/include/all-keybindings.h   |  2 ++
 src/include/prefs.h             |  3 ++-
 src/org.mate.marco.gschema.xml  |  5 ++++
 src/ui/ui.c                     |  8 ++++++
 8 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/po/zh_CN.po b/po/zh_CN.po
index ad1d1eb..4399cda 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -42,6 +42,9 @@ msgstr "显示面板的“运行应用程序”对话框"
 msgid "Show the panel's main menu"
 msgstr "显示面板主菜单"
 
+msgid "Show the panel's main menu of kiran"
+msgstr "显示开始菜单"
+
 #: ../src/50-marco-desktop-key.xml.in.h:4
 #: ../src/org.mate.marco.gschema.xml.h:101
 msgid "Take a screenshot"
diff --git a/src/50-marco-desktop-key.xml.in b/src/50-marco-desktop-key.xml.in
index 219109e..1719291 100644
--- a/src/50-marco-desktop-key.xml.in
+++ b/src/50-marco-desktop-key.xml.in
@@ -5,6 +5,8 @@
 
 	<KeyListEntry name="panel-main-menu" _description="Show the panel's main menu" />
 
+	<KeyListEntry name="panel-kiran-menu" _description="Show the panel's main menu of kiran" />
+
 	<KeyListEntry name="run-command-screenshot" _description="Take a screenshot" />
 
 	<KeyListEntry name="run-command-window-screenshot" _description="Take a screenshot of a window" />
diff --git a/src/core/atomnames.h b/src/core/atomnames.h
index 3744f42..48582aa 100644
--- a/src/core/atomnames.h
+++ b/src/core/atomnames.h
@@ -64,6 +64,7 @@ item(_GTK_SHOW_WINDOW_MENU)
 item(_MATE_PANEL_ACTION)
 item(_MATE_PANEL_ACTION_MAIN_MENU)
 item(_MATE_PANEL_ACTION_RUN_DIALOG)
+item(_MATE_PANEL_ACTION_KIRAN_MENU)
 item(_MARCO_SENTINEL)
 item(_MARCO_VERSION)
 item(WM_CLIENT_MACHINE)
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 83ff985..542c89f 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -2917,6 +2917,54 @@ handle_panel (MetaDisplay    *display,
   meta_error_trap_pop (display, FALSE);
 }
 
+static void
+handle_kiran_panel (MetaDisplay    *display,
+                           MetaScreen     *screen,
+                           MetaWindow     *window,
+                           XEvent         *event,
+                           MetaKeyBinding *binding)
+  {
+    /*MetaKeyBindingAction action = binding->handler->data;*/
+    MetaKeyBindingAction action = META_KEYBINDING_ACTION_KIRAN_PANEL_MENU;
+    Atom action_atom;
+    XClientMessageEvent ev;
+  
+    action_atom = None;
+    switch (action)
+      {
+      /* FIXME: The numbers are wrong */
+      case META_KEYBINDING_ACTION_KIRAN_PANEL_MENU:
+        action_atom = display->atom__MATE_PANEL_ACTION_KIRAN_MENU;
+        break;
+      default:
+        return;
+      }
+  
+    ev.type = ClientMessage;
+    ev.window = screen->xroot;
+    ev.message_type = display->atom__MATE_PANEL_ACTION;
+    ev.format = 32;
+    ev.data.l[0] = action_atom;
+    ev.data.l[1] = event->xkey.time;
+  
+    meta_topic (META_DEBUG_KEYBINDINGS,
+                "Sending panel message with timestamp %lu, and turning mouse_mode "
+                "off due to keybinding press\n", event->xkey.time);
+    display->mouse_mode = FALSE;
+  
+    meta_error_trap_push (display);
+  
+    /* Release the grab for the panel before sending the event */
+    XUngrabKeyboard (display->xdisplay, event->xkey.time);
+    XSendEvent (display->xdisplay,
+  	      screen->xroot,
+  	      False,
+  	      StructureNotifyMask,
+  	      (XEvent*) &ev);
+  
+    meta_error_trap_pop (display, FALSE);
+}
+
 static void
 handle_activate_window_menu (MetaDisplay    *display,
                       MetaScreen     *screen,
diff --git a/src/include/all-keybindings.h b/src/include/all-keybindings.h
index cba8e9f..a7ade33 100644
--- a/src/include/all-keybindings.h
+++ b/src/include/all-keybindings.h
@@ -154,6 +154,8 @@ keybind (show-desktop, handle_show_desktop, 0, 0)
 keybind (panel-main-menu, handle_panel, META_KEYBINDING_ACTION_PANEL_MAIN_MENU, 0)
 keybind (panel-run-dialog, handle_panel, META_KEYBINDING_ACTION_PANEL_RUN_DIALOG, 0)
 
+keybind (panel-kiran-menu, handle_kiran_panel, META_KEYBINDING_ACTION_KIRAN_PANEL_MENU, 0)
+
 /* Yes, the param is offset by one.  Historical reasons.  (Maybe worth fixing
  * at some point.)  The description is NULL here because the stanza is
  * irregularly shaped in marco.schemas.in.  This will probably be fixed
diff --git a/src/include/prefs.h b/src/include/prefs.h
index 34ab802..eda0693 100644
--- a/src/include/prefs.h
+++ b/src/include/prefs.h
@@ -205,7 +205,8 @@ typedef enum _MetaKeyBindingAction
   META_KEYBINDING_ACTION_COMMAND_9,
   META_KEYBINDING_ACTION_COMMAND_10,
   META_KEYBINDING_ACTION_COMMAND_11,
-  META_KEYBINDING_ACTION_COMMAND_12
+  META_KEYBINDING_ACTION_COMMAND_12,
+  META_KEYBINDING_ACTION_KIRAN_PANEL_MENU
 } MetaKeyBindingAction;
 
 typedef struct
diff --git a/src/org.mate.marco.gschema.xml b/src/org.mate.marco.gschema.xml
index 94f63b4..5716af3 100644
--- a/src/org.mate.marco.gschema.xml
+++ b/src/org.mate.marco.gschema.xml
@@ -607,6 +607,11 @@
       <summary>Show the panel's main menu</summary>
       <description>The format looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1". The parser is fairly liberal and allows lower or upper case, and also abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;". If you set the option to the special string "disabled", then there will be no keybinding for this action.</description>
     </key>
+    <key name="panel-kiran-menu" type="s">
+      <default>'&lt;Super&gt;'</default>
+      <summary>Show the panel's main menu of kiran</summary>
+      <description>The format looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1". The parser is fairly liberal and allows lower or upper case, and also abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;". If you set the option to the special string "disabled", then there will be no keybinding for this action.</description>
+    </key>
     <key name="panel-run-dialog" type="s">
       <default>'&lt;Alt&gt;F2'</default>
       <summary>Show the panel's "Run Application" dialog box</summary>
diff --git a/src/ui/ui.c b/src/ui/ui.c
index ed2c577..ddfa9bc 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -772,6 +772,14 @@ meta_ui_parse_accelerator (const char          *accel,
     return TRUE;
 
   meta_ui_accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
+  if(gdk_mask & GDK_SUPER_MASK)
+  {	
+	unsigned char super_L_keycode=0;
+	Display *display = XOpenDisplay(NULL);
+	super_L_keycode = XKeysymToKeycode(display , XK_Super_L);
+	gdk_code = super_L_keycode;
+	gdk_mask = 0;
+  }
   if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
     return FALSE;
 
-- 
2.27.0

