Skip to content

Move MessageWindow from core to winAPI module #14035

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

Merged
merged 34 commits into from
Aug 31, 2022
Merged

Conversation

seanbudd
Copy link
Member

@seanbudd seanbudd commented Aug 19, 2022

Link to issue number:

None

Summary of the issue:

core.main is too long of a function.
Work was performed in the message window section of core.main.
In efforts to reduce the length of core.main, the MessageWindow should be factored out to winAPI.

In doing this, a bug was discovered that orientation status was not incorrectly reported when the state had not changed.
The previous orientation status was not being correctly cached.

Description of user facing changes

A bug was fixed where orientation changes were incorrectly reported when the orientation has not changed.

When the power status changes, the amount of battery time remaining is now reported to be consistent with script_say_battery_status.

Description of development approach

Code has been migrated and reorganised to purpose driven modules.

Testing strategy:

Manually tested:

  • power state changes (disconnect and connecting power to laptop, performing script_say_battery_status)
  • session state changes (locking and unlocking device)
  • display state changes (rotating hybrid tablet device)

Known issues with pull request:

None

Change log entries:

refer to PR diff

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • Security precautions taken.

@seanbudd seanbudd self-assigned this Aug 19, 2022
@AppVeyorBot
Copy link

See test results for failed build of commit 981b655de7

@seanbudd seanbudd changed the title Move code from core to winAPI module Move MessageWindow from core to winAPI module Aug 19, 2022
@seanbudd seanbudd added the merge-early Merge Early in a developer cycle label Aug 19, 2022
@AppVeyorBot
Copy link

See test results for failed build of commit 7f96082d17

@seanbudd seanbudd marked this pull request as ready for review August 22, 2022 04:10
@seanbudd seanbudd requested a review from a team as a code owner August 22, 2022 04:10
@seanbudd seanbudd requested a review from feerrenrut August 22, 2022 04:10
Comment on lines -636 to -644
self.orientationCoordsCache = (width,height)
if width > height:
# If the height and width are the same, it's actually a screen flip, and we do want to alert of those!
if self.orientationStateCache == self.ORIENTATION_LANDSCAPE and self.orientationCoordsCache != (width,height):
return
#Translators: The screen is oriented so that it is wider than it is tall.
ui.message(_("Landscape" ))
self.orientationStateCache = self.ORIENTATION_LANDSCAPE
else:
if self.orientationStateCache == self.ORIENTATION_PORTRAIT and self.orientationCoordsCache != (width,height):
Copy link
Member Author

Choose a reason for hiding this comment

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

setting the cache on line 636 means line 639 and line 645 will never be true, so non-changes of orientation are incorrectly reported.

@AppVeyorBot
Copy link

  • PASS: Translation comments check.
  • PASS: Unit tests.
  • PASS: Lint check.
  • Build execution time has reached the maximum allowed time for your plan (60 minutes).

See test results for failed build of commit 0a7ac9dc44

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

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

This is definitely an improvement.
Let's look for opportunites to add unit testing while at it, to make future modifications in the area easier.

@AppVeyorBot
Copy link

  • PASS: Translation comments check.
  • PASS: Unit tests.
  • PASS: Lint check.
  • Build execution time has reached the maximum allowed time for your plan (60 minutes).

See test results for failed build of commit f4ac14906b

@seanbudd seanbudd marked this pull request as draft August 25, 2022 01:52
@AppVeyorBot
Copy link

See test results for failed build of commit 91f7de5982

@seanbudd seanbudd marked this pull request as ready for review August 25, 2022 02:56
@seanbudd seanbudd requested a review from feerrenrut August 25, 2022 02:57
Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

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

Overall looks good.

@@ -137,6 +137,14 @@ def windowProc(self, hwnd: HWNDValT, msg: int, wParam: int, lParam: int) -> None
@param lParam: Additional message information.
"""
post_windowMessageReceipt.notify(msg=msg, wParam=wParam, lParam=lParam)
Copy link
Contributor

Choose a reason for hiding this comment

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

post_ should mean "after it has been handled", however given the naming of this extension point it is a bit of a fuzzy concept. Can you confirm that this is the original order of extension point vs handleWindowsMessage?

The reason to have consistency here is if the extension point listener wants to check state after it has been modified by NVDA.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, this is keeping the original order.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, I believe post_ means "after the message has been received".

Copy link
Contributor

Choose a reason for hiding this comment

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

It probably should have been named pre/post_handleWindowMessage

Copy link
Member Author

Choose a reason for hiding this comment

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

This can be easily renamed in this PR, the old symbol has been deprecated/moved anyway.
I'll change this to pre_handleWindowMessage?

@seanbudd seanbudd marked this pull request as draft August 30, 2022 01:14
@seanbudd seanbudd marked this pull request as ready for review August 30, 2022 02:47
@seanbudd seanbudd requested a review from feerrenrut August 30, 2022 02:47
@@ -3,6 +3,11 @@
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

"""
When working on this file, consider moving to winAPI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave these comments out for now, it isn't clear where the line is for what is "generic Windows abstraction" vs core NVDA behavior. Many files probably have these two concepts coupled, and it will require a careful approach to extract the generic Windows abstraction part into winAPI.

@@ -6,6 +6,8 @@
"""handles touchscreen interaction (Windows 8 and later).
Used to provide input gestures for touchscreens, touch modes and other support facilities.
In order to use touch features, NVDA must be installed on a touchscreen computer running Windows 8 and later.

When working on this file, consider moving to winAPI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here.

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

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

I'm a bit worried that the scope of this refactor is growing. This increases the changes of introducing regressions.

_orientationState: Optional[OrientationState] = None


def initialize():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this module be excluded from the add-on API? Given this is new code, and we don't know there is a demand for it within the API, keeping it excluded will let us iterate safely on the design.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also goes for the other new modules that don't need to be exposed.

class SystemMetrics(IntEnum):
"""
GetSystemMetrics constants
https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-getsystemmetrics
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are winuser constants, the values living in winUser makes makes them easier to find.
The options I see right now:

  • Keep these in winUser, moving that to winAPI later.
  • Add a new winUser to winAPI (containing only these constants) now, accepting that it will be confusing to have two identically named modules.
  • Rename this to winUserConstants.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed, this has been moved to winAPI.winUser.constants

@seanbudd seanbudd marked this pull request as draft August 30, 2022 04:07
@seanbudd seanbudd marked this pull request as ready for review August 30, 2022 06:30
@seanbudd seanbudd requested a review from feerrenrut August 30, 2022 06:31
@AppVeyorBot
Copy link

See test results for failed build of commit 0ae423b959

Copy link
Contributor

@feerrenrut feerrenrut left a comment

Choose a reason for hiding this comment

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

Looks good.

@AppVeyorBot
Copy link

See test results for failed build of commit 82d6a27496

@seanbudd seanbudd merged commit 2392d13 into master Aug 31, 2022
@seanbudd seanbudd deleted the moveCodeToWinAPI branch August 31, 2022 05:55
@nvaccessAuto nvaccessAuto added this to the 2022.4 milestone Aug 31, 2022
@jage9
Copy link
Contributor

jage9 commented Sep 13, 2022

Previously, the battery status command read the percent followed by the charge state. This now seems to be reversed, which to me is less than ideal. Is there a reason to flip this information around? The numeric to me is the more important bit of information.

@seanbudd
Copy link
Member Author

@jage9 - could you open a new issue or GitHub discussion for this?
Discussions on closed pull requests are easily lost and without more feedback it is hard to know what the preferred behaviour is for most people.

In the issue, please say why this information is more important to you in that order.
For example, I imagine most people know if their AC is disconnected or connected, so the % is more important.

@seanbudd
Copy link
Member Author

The API changes for this issue have been announced here: https://groups.google.com/a/nvaccess.org/g/nvda-api/c/7-8ddyZzloQ/m/6L_Jrpy3BQAJ

This was merged before the mailing list was announced. However, we have announced API changes in 2022.3.3 and 2023.1, so it may be misleading to skip the API changes in 2022.4 (when the mailing list was created).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-early Merge Early in a developer cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants