Skip to content

Commit

Permalink
macOS: Change drag copy shortcut from Command to Option (#7325)
Browse files Browse the repository at this point in the history
macOS: Replace Command + Drag shortcut key with Option + Drag
Add new header `KeyboardShortcuts.h` for platform-specific keyboard mappings

---------

Co-authored-by: Michael Gregorius <[email protected]>
  • Loading branch information
tresf and michaelgregorius authored Feb 9, 2025
1 parent 4a089a1 commit 30216aa
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 22 deletions.
77 changes: 77 additions & 0 deletions include/KeyboardShortcuts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* KeyboardShortcuts.h - Cross-platform handling of keyboard modifier keys
*
* Copyright (c) 2025 Michael Gregorius
* Copyright (c) 2025 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_KEYBOARDSHORTCUTS_H
#define LMMS_KEYBOARDSHORTCUTS_H

#include "lmmsconfig.h"

#include "qnamespace.h"


namespace lmms
{

// Qt on macOS maps:
// - ControlModifier --> Command keys
// - MetaModifier value --> Control keys
// - Qt::AltModifier --> Option keys
//
// Our UI hints need to be adjusted to accommodate for this
constexpr const char* UI_CTRL_KEY =
#ifdef LMMS_BUILD_APPLE
"";
#else
"Ctrl";
#endif

constexpr const char* UI_ALT_KEY =
#ifdef LMMS_BUILD_APPLE
"Option";
#else
"Alt";
#endif

// UI hint for copying OR linking a UI component
// this MUST be consistent with KBD_COPY_MODIFIER
constexpr const char* UI_COPY_KEY =
#ifdef LMMS_BUILD_APPLE
UI_ALT_KEY;
#else
UI_CTRL_KEY;
#endif

// Shortcut for copying OR linking a UI component
// this MUST be consistent with UI_COPY_KEY
constexpr Qt::KeyboardModifier KBD_COPY_MODIFIER =
#ifdef LMMS_BUILD_APPLE
Qt::AltModifier;
#else
Qt::ControlModifier;
#endif

} // namespace lmms

#endif // LMMS_KEYBOARDSHORTCUTS_H
9 changes: 0 additions & 9 deletions include/lmms_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ constexpr char LADSPA_PATH_SEPERATOR =
#define LMMS_STRINGIFY(s) LMMS_STR(s)
#define LMMS_STR(PN) #PN

// Abstract away GUI CTRL key (linux/windows) vs ⌘ (apple)
constexpr const char* UI_CTRL_KEY =
#ifdef LMMS_BUILD_APPLE
"";
#else
"Ctrl";
#endif


} // namespace lmms

#endif // LMMS_TYPES_H
3 changes: 2 additions & 1 deletion src/core/AutomationClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "AutomationNode.h"
#include "AutomationClipView.h"
#include "AutomationTrack.h"
#include "KeyboardShortcuts.h"
#include "LocaleHelper.h"
#include "Note.h"
#include "PatternStore.h"
Expand Down Expand Up @@ -952,7 +953,7 @@ QString AutomationClip::name() const
{
return m_objects.front()->fullDisplayName();
}
return tr( "Drag a control while pressing <%1>" ).arg(UI_CTRL_KEY);
return tr( "Drag a control while pressing <%1>" ).arg(UI_COPY_KEY);
}


Expand Down
3 changes: 2 additions & 1 deletion src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ControllerConnection.h"
#include "embed.h"
#include "GuiApplication.h"
#include "KeyboardShortcuts.h"
#include "MainWindow.h"
#include "StringPairDrag.h"
#include "Clipboard.h"
Expand Down Expand Up @@ -171,7 +172,7 @@ void AutomatableModelView::unsetModel()

void AutomatableModelView::mousePressEvent( QMouseEvent* event )
{
if( event->button() == Qt::LeftButton && event->modifiers() & Qt::ControlModifier )
if (event->button() == Qt::LeftButton && event->modifiers() & KBD_COPY_MODIFIER)
{
new gui::StringPairDrag( "automatable_model", QString::number( modelUntyped()->id() ), QPixmap(), widget() );
event->accept();
Expand Down
1 change: 1 addition & 0 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Instrument.h"
#include "InstrumentTrack.h"
#include "InstrumentTrackWindow.h"
#include "KeyboardShortcuts.h"
#include "MainWindow.h"
#include "PatternStore.h"
#include "PluginFactory.h"
Expand Down
1 change: 1 addition & 0 deletions src/gui/ProjectNotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "embed.h"
#include "Engine.h"
#include "GuiApplication.h"
#include "KeyboardShortcuts.h"
#include "MainWindow.h"
#include "Song.h"

Expand Down
2 changes: 1 addition & 1 deletion src/gui/StringPairDrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ StringPairDrag::StringPairDrag( const QString & _key, const QString & _value,
auto m = new QMimeData();
m->setData( mimeType( MimeType::StringPair ), txt.toUtf8() );
setMimeData( m );
exec( Qt::LinkAction, Qt::LinkAction );
exec( Qt::CopyAction, Qt::CopyAction );
}


Expand Down
7 changes: 4 additions & 3 deletions src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "InstrumentTrackView.h"
#include "KeyboardShortcuts.h"
#include "MidiClip.h"
#include "MidiClipView.h"
#include "Note.h"
Expand Down Expand Up @@ -633,7 +634,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
auto pClip = dynamic_cast<PatternClip*>(m_clip);
const bool knifeMode = m_trackView->trackContainerView()->knifeMode();

if ( me->modifiers() & Qt::ControlModifier && !(sClip && knifeMode) )
if (me->modifiers() & KBD_COPY_MODIFIER && !(sClip && knifeMode))
{
if( isSelected() )
{
Expand Down Expand Up @@ -726,7 +727,7 @@ void ClipView::mousePressEvent( QMouseEvent * me )
QString hint = m_action == Action::Move || m_action == Action::MoveSelection
? tr( "Press <%1> and drag to make a copy." )
: tr( "Press <%1> for free resizing." );
m_hint = TextFloat::displayMessage( tr( "Hint" ), hint.arg(UI_CTRL_KEY),
m_hint = TextFloat::displayMessage( tr( "Hint" ), hint.arg(UI_COPY_KEY),
embed::getIconPixmap( "hint" ), 0 );
}
}
Expand Down Expand Up @@ -824,7 +825,7 @@ void ClipView::mouseMoveEvent( QMouseEvent * me )
}
}

if( me->modifiers() & Qt::ControlModifier )
if (me->modifiers() & KBD_COPY_MODIFIER)
{
delete m_hint;
m_hint = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "GuiApplication.h"
#include "FontHelper.h"
#include "InstrumentTrack.h"
#include "KeyboardShortcuts.h"
#include "MainWindow.h"
#include "MidiClip.h"
#include "PatternStore.h"
Expand Down
1 change: 1 addition & 0 deletions src/gui/editors/TimeLineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "ConfigManager.h"
#include "embed.h"
#include "GuiApplication.h"
#include "KeyboardShortcuts.h"
#include "NStateButton.h"
#include "TextFloat.h"

Expand Down
6 changes: 3 additions & 3 deletions src/gui/tracks/TrackOperationsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "embed.h"
#include "Engine.h"
#include "InstrumentTrackView.h"
#include "KeyboardShortcuts.h"
#include "PixmapButton.h"
#include "Song.h"
#include "StringPairDrag.h"
Expand Down Expand Up @@ -180,9 +181,8 @@ TrackOperationsWidget::TrackOperationsWidget( TrackView * parent ) :
*/
void TrackOperationsWidget::mousePressEvent( QMouseEvent * me )
{
if( me->button() == Qt::LeftButton &&
me->modifiers() & Qt::ControlModifier &&
m_trackView->getTrack()->type() != Track::Type::Pattern)
if (me->button() == Qt::LeftButton && me->modifiers() & KBD_COPY_MODIFIER &&
m_trackView->getTrack()->type() != Track::Type::Pattern)
{
DataFile dataFile( DataFile::Type::DragNDropData );
m_trackView->getTrack()->saveState( dataFile, dataFile.content() );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "embed.h"
#include "CaptionMenu.h"
#include "ConfigManager.h"
#include "KeyboardShortcuts.h"
#include "SimpleTextFloat.h"

namespace lmms::gui
Expand Down Expand Up @@ -125,7 +126,7 @@ void Fader::mouseMoveEvent(QMouseEvent* mouseEvent)
void Fader::mousePressEvent(QMouseEvent* mouseEvent)
{
if (mouseEvent->button() == Qt::LeftButton &&
!(mouseEvent->modifiers() & Qt::ControlModifier))
!(mouseEvent->modifiers() & KBD_COPY_MODIFIER))
{
AutomatableModel* thisModel = model();
if (thisModel)
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "CaptionMenu.h"
#include "ControllerConnection.h"
#include "GuiApplication.h"
#include "KeyboardShortcuts.h"
#include "LocaleHelper.h"
#include "MainWindow.h"
#include "ProjectJournal.h"
Expand Down Expand Up @@ -155,7 +156,7 @@ void FloatModelEditorBase::dropEvent(QDropEvent * de)
void FloatModelEditorBase::mousePressEvent(QMouseEvent * me)
{
if (me->button() == Qt::LeftButton &&
! (me->modifiers() & Qt::ControlModifier) &&
! (me->modifiers() & KBD_COPY_MODIFIER) &&
! (me->modifiers() & Qt::ShiftModifier))
{
AutomatableModel *thisModel = model();
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/LcdFloatSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "embed.h"
#include "GuiApplication.h"
#include "FontHelper.h"
#include "KeyboardShortcuts.h"
#include "MainWindow.h"
#include "lmms_math.h"

Expand Down Expand Up @@ -139,7 +140,7 @@ void LcdFloatSpinBox::mousePressEvent(QMouseEvent* event)
m_intStep = event->x() < m_wholeDisplay.width();

if (event->button() == Qt::LeftButton &&
!(event->modifiers() & Qt::ControlModifier) &&
!(event->modifiers() & KBD_COPY_MODIFIER) &&
event->y() < m_wholeDisplay.cellHeight() + 2)
{
m_mouseMoving = true;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/LcdSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QInputDialog>

#include "LcdSpinBox.h"
#include "KeyboardShortcuts.h"
#include "CaptionMenu.h"


Expand Down Expand Up @@ -79,7 +80,7 @@ void LcdSpinBox::contextMenuEvent(QContextMenuEvent* event)
void LcdSpinBox::mousePressEvent( QMouseEvent* event )
{
if( event->button() == Qt::LeftButton &&
! ( event->modifiers() & Qt::ControlModifier ) &&
! (event->modifiers() & KBD_COPY_MODIFIER) &&
event->y() < cellHeight() + 2 )
{
m_mouseMoving = true;
Expand Down

0 comments on commit 30216aa

Please sign in to comment.