From fefc89f7b150b44e1efe284e918c8cdd734e9e64 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Tue, 24 Nov 2015 18:56:51 -0500 Subject: [PATCH] change keyboard shortcut modifiers to use Command on OSX instead of Control, and send a "focus" event for window focus --- pd/nw/index.js | 62 +++++++++++++++++++++++++++------------------- pd/nw/pd_canvas.js | 18 ++++++++++++-- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/pd/nw/index.js b/pd/nw/index.js index 8ef53a3fe..be8367111 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -75,6 +75,10 @@ function open_external_doc(target) { gui.Shell.openExternal(target); } +function nw_window_focus_callback() { + pdgui.post("pd window was focused"); +} + function add_events() { // Find bar var find_bar = document.getElementById("console_find_text"); @@ -101,6 +105,10 @@ function add_events() { gui.Window.get().on("close", function() { pdgui.menu_quit(); }); + // Focus callback for OSX + gui.Window.get().on("focus", function() { + nw_window_focus_callback(); + }); // Open dialog document.getElementById("fileDialog").setAttribute("nwworkingdir", pwd); document.getElementById("fileDialog").setAttribute("accept", @@ -296,6 +304,8 @@ function pdmenu_irc () { // Menus for the main Pd window function nw_create_pd_window_menus () { + // Command key for OSX, Control for GNU/Linux and Windows + var cmd_or_ctrl = process.platform === "darwin" ? "cmd" : "ctrl"; // Window menu var windowMenu = new gui.Menu({ type: "menubar" @@ -315,14 +325,14 @@ function nw_create_pd_window_menus () { label: l("menu.new"), click: pdgui.menu_new, key: "n", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.new.tt") })); fileMenu.append(new gui.MenuItem({ label: l("menu.open"), key: "o", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.open.tt"), click: function (){ var input, chooser, @@ -369,7 +379,7 @@ function nw_create_pd_window_menus () { enabled: false, key: "s", tooltip: l("menu.save.tt"), - modifiers: "ctrl" + modifiers: cmd_or_ctrl })); fileMenu.append(new gui.MenuItem({ @@ -378,7 +388,7 @@ function nw_create_pd_window_menus () { enabled: false, key: "S", tooltip: l("menu.saveas_tt"), - modifiers: "ctrl" + modifiers: cmd_or_ctrl })); if (pdgui.k12_mode == 0) { @@ -391,7 +401,7 @@ function nw_create_pd_window_menus () { label: l("menu.message"), click: pdgui.menu_send, key: "m", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.message_tt") })); @@ -417,7 +427,7 @@ function nw_create_pd_window_menus () { label: l("menu.quit"), click: pdgui.menu_quit, key: "q", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.quit_tt") })); @@ -438,7 +448,7 @@ function nw_create_pd_window_menus () { document.execCommand("copy"); }, key: "c", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.copy_tt") })); @@ -465,7 +475,7 @@ function nw_create_pd_window_menus () { } }, key: "a", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.selectall_tt") })); @@ -479,7 +489,7 @@ function nw_create_pd_window_menus () { gui.Window.get().zoomLevel += 1; }, key: "=", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.zoomin_tt") })); @@ -489,7 +499,7 @@ function nw_create_pd_window_menus () { gui.Window.get().zoomLevel -= 1; }, key: "-", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.zoomout_tt") })); @@ -517,7 +527,7 @@ function nw_create_pd_window_menus () { } }, key: "f", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.find_tt") })); @@ -525,7 +535,7 @@ function nw_create_pd_window_menus () { label: l("menu.preferences"), click: pdgui.open_prefs, key: "p", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.preferences_tt") })); @@ -547,7 +557,7 @@ function nw_create_pd_window_menus () { pdgui.raise_next("pd_window"); }, //key: "c", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.nextwin_tt") })); @@ -557,7 +567,7 @@ function nw_create_pd_window_menus () { pdgui.raise_prev("pd_window"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.prevwin_tt") })); @@ -577,7 +587,7 @@ function nw_create_pd_window_menus () { pdgui.pdsend("pd dsp 1"); }, key: "/", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.audio_on_tt") })); @@ -587,7 +597,7 @@ function nw_create_pd_window_menus () { pdgui.pdsend("pd dsp 0"); }, key: ".", - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.audio_off_tt") })); @@ -601,7 +611,7 @@ function nw_create_pd_window_menus () { pdgui.pd_doc_open("doc/7.stuff/tools", "testtone.pd"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.test_tt") })); @@ -611,7 +621,7 @@ function nw_create_pd_window_menus () { pdgui.pd_doc_open("doc/7.stuff/tools", "load-meter.pd"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.loadmeter_tt") })); @@ -631,7 +641,7 @@ function nw_create_pd_window_menus () { pdgui.pd_doc_open("doc/1.manual", "1.introduction.txt"); }, //key: "c", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.about_tt") })); @@ -641,7 +651,7 @@ function nw_create_pd_window_menus () { pdgui.pd_doc_open("doc/1.manual", "index.htm"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.manual_tt") })); @@ -649,7 +659,7 @@ function nw_create_pd_window_menus () { label: l("menu.browser"), click: pdmenu_help_browser, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.browser_tt") })); @@ -663,7 +673,7 @@ function nw_create_pd_window_menus () { pdgui.external_doc_open("http://disis.music.vt.edu/listinfo/l2ork-dev"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.l2ork_list_tt") })); @@ -673,7 +683,7 @@ function nw_create_pd_window_menus () { pdgui.external_doc_open("http://puredata.info/community/lists"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.pd_list_tt") })); @@ -683,7 +693,7 @@ function nw_create_pd_window_menus () { pdgui.external_doc_open("http://forum.pdpatchrepo.info/"); }, //key: "a", - //modifiers: "ctrl", + //modifiers: cmd_or_ctrl, tooltip: l("menu.forums_tt") })); @@ -693,7 +703,7 @@ function nw_create_pd_window_menus () { gui.Window.get().showDevTools(); }, key: "b", // temporary convenience shortcut-- can change if needed - modifiers: "ctrl", + modifiers: cmd_or_ctrl, tooltip: l("menu.devtools_tt") })); @@ -703,7 +713,7 @@ function nw_create_pd_window_menus () { // pdgui.external_doc_open("irc://irc.freenode.net/dataflow"); // }, // //key: "a", - // //modifiers: "ctrl", + // //modifiers: cmd_or_ctrl, // tooltip: l("menu.irc_tt") //})); diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index 4c3154745..622c204e8 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -46,6 +46,10 @@ function encode_for_dialog(s) { return s; } +function nw_window_focus_callback() { + pdgui.post("window was focused"); +} + // These three functions need to be inside canvas_events closure function canvas_find_whole_word(elem) { canvas_events.match_words(elem.checked); @@ -392,6 +396,7 @@ var canvas_events = (function() { ); document.querySelector("#canvas_find_button").addEventListener("click", events.find_click); + // We need to separate these into nw_window events and html5 DOM events // closing the Window // this isn't actually closing the window yet gui.Window.get().on("close", function() { @@ -407,6 +412,9 @@ var canvas_events = (function() { gui.Window.get().on("resize", function() { pdgui.gui_canvas_getscroll(name); }); + gui.Window.get().on("focus", function() { + nw_window_focus_callback(); + }); // set minimum window size gui.Window.get().setMinimumSize(150, 100); @@ -521,10 +529,16 @@ function register_canvas_id(cid) { // Otherwise we might set the svg size to the window viewport, only to have // the menu push down the svg viewport and create scrollbars. Those same // scrollbars will get erased once canvas_map triggers, causing a quick - // (and annoying) scrollbar flash - nw_create_patch_window_menus(cid); + // (and annoying) scrollbar flash. + // For OSX, we have a single menu and just track which window has the + // focus. + if (process.platform !== "darwin") { + nw_create_patch_window_menus(cid); + } create_popup_menu(cid); canvas_events.register(cid); + // Trigger a "focus" event so that OSX updates the menu for this window + nw_window_focus_callback(); canvas_events.normal(); pdgui.canvas_map(cid); // side-effect: triggers gui_canvas_getscroll from Pd } -- GitLab