Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QT GUI: close window with cmd-w on macos #4821

Merged
merged 5 commits into from
Mar 26, 2020

Conversation

dyfer
Copy link
Member

@dyfer dyfer commented Mar 11, 2020

Purpose and Motivation

This is a workaround for a workaround introduced in #4105 (which fixed #4058, but caused #4309). This fixes #4309.

It's not pretty, but it works. I hope that at some point someone looks into a proper fix that's hacked in #4105, but until then it would be great to have the ability to close windows from the keyboard again...

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • This PR is ready for review

@dyfer dyfer added os: macOS comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead labels Mar 11, 2020
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general approach looks OK but please document this by adding to the comment above event->accept().

there's an issue i noticed -- combos like Cmd+Alt+W are not being filtered correctly, they don't close the window (good) but also cause a 'bad input' alert sound (bad).

@dyfer
Copy link
Member Author

dyfer commented Mar 13, 2020

thanks @brianlheim for looking at this, I was hoping for your input.
Thanks for catching the combo input, I'll fix it and I'll add the comment.
So I gather that 3 #ifdefs in that function (2 added by this PR) are OK/unavoidable?

@dyfer dyfer force-pushed the topic/cmd-w-close-window-macos branch 2 times, most recently from eb7253e to 3488bae Compare March 13, 2020 05:05
@dyfer
Copy link
Member Author

dyfer commented Mar 13, 2020

I addressed the issue with combo input. I also added comments. How does it look now?

I rebased this PR on top of 3.11, so the CI passes. I think that after the current release process is completed (we merge 3.11 into master and then master into develop) this should show up as a single commit...(?)
EDIT: unless this is something we could put into 3.11.1 and then I'd just change the destination branch to 3.11?

this is a workaround for a workaround introduced in supercollider#4105, which fixed supercollider#4058, but caused supercollider#4309
@dyfer dyfer force-pushed the topic/cmd-w-close-window-macos branch from 3488bae to 28682e6 Compare March 13, 2020 05:34
@mossheim mossheim changed the base branch from develop to 3.11 March 13, 2020 12:27
@mossheim
Copy link
Contributor

@dyfer changed the base to 3.11, this can go into 3.11.1

@mossheim
Copy link
Contributor

So I gather that 3 #ifdefs in that function (2 added by this PR) are OK/unavoidable?

i'm still thinking about it, would prefer to have just one

// of doing this.
// In order to still allow closing GUI windows with "cmd-w", we do not accept modifier keys
// alone, as well as the "cmd-w" combination itself, so that they propagate further
// (see isKeyEvent and isCloseEvent above).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from this comment, i still don't understand why you filter out modifier keys alone.

@dyfer
Copy link
Member Author

dyfer commented Mar 13, 2020

I tried to clarify the comment, I hope it's more clear now?

I also tried to put it in a single #ifdef. It looks cleaner now, but we check for event type twice. Is this OK or should I revert it to 3 ifdefs and better (I think?) performance? wouldn't performance aspect be negligible here?

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dyfer . i prefer the single #ifdef block. this is not a performance critical section, it's fine in that regard.

i'm noting we're now only accepting key events. i think this is OK, maybe even more in line with what i was trying to do here before

if ((kevent->key() == Qt::Key_W) && (kevent->modifiers() == Qt::ControlModifier)) {
isCloseEvent = true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the local variables and place all this logic inside the if below, since it only matters if(result). you can also condense these two checks into a single if. i am guessing you split it to make this clearer, but in my opinion keeping the logic condensed and having an explanatory comment is much nicer:

if (result and key press type) {
  static cast
  if (is not close and is not unknown) {
    accept()
  }
}

bool isCloseEvent = false;
bool isKeyEvent = false;
if (event->type() == QEvent::KeyPress) {
QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to use auto when it doesn't obscure the type, and especially when the type is already known from the right hand side of an initialization (for example a cast or obvious function name). this keeps code concise and makes it easier to read and maintain.

@dyfer
Copy link
Member Author

dyfer commented Mar 25, 2020

Thank you for the feedback and suggestions @brianlheim, I simplified the logic.

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@mossheim mossheim merged commit e652302 into supercollider:3.11 Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead os: macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sclang: cmd+w doesn't close child windows keyDownAction triggers a warning/error (sound) message on Mac
2 participants