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

Initialize Layer State on startup #8318

Merged
merged 4 commits into from
Jul 27, 2020

Conversation

drashna
Copy link
Member

@drashna drashna commented Mar 5, 2020

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized. It's set to 0 directly, by default, but the callback functions are never actually called. This creates some inconsistency in the behavior for end users. This adds a simple "clear" that triggers the callback on startup. This should produce more consistent behavior between the two functions and layer masks.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@drashna drashna added the core label Mar 5, 2020
@drashna drashna requested a review from a team March 5, 2020 06:52
@drashna
Copy link
Member Author

drashna commented Mar 9, 2020

hmm, only issue is that the mock test now fails.

Probably why this wasn't implemented before.
Unfortunately, I'm not sure how to fix the test. :(

@drashna drashna added the on hold label Mar 9, 2020
@drashna drashna requested a review from a team March 9, 2020 02:22
@fauxpark
Copy link
Member

fauxpark commented Mar 9, 2020

Haven't we run into this before?

@drashna
Copy link
Member Author

drashna commented Mar 9, 2020

Yes. Specifically with re-initing on eeprom reset, IIRC. But it was failing at a different point.

Honestly, I suspect that the testing could use some TLC.

@drashna drashna force-pushed the tmk_core/layer_state_trash branch from a3721df to c4d7e5b Compare March 10, 2020 07:56
@kitlaan
Copy link
Contributor

kitlaan commented May 19, 2020

While I'm not sure what the intent of the gunit tests are... This causes them to go away with your original change:

diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
index 8caf1fca4..926b31512 100644
--- a/tests/test_common/test_fixture.cpp
+++ b/tests/test_common/test_fixture.cpp
@@ -22,7 +22,8 @@ using testing::Return;
 
 void TestFixture::SetUpTestCase() {
     TestDriver driver;
-    EXPECT_CALL(driver, send_keyboard_mock(_));
+    // Once for initial initialization, and again for bootmagic init
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(2);
     keyboard_init();
 }
 
@@ -32,6 +33,7 @@ TestFixture::TestFixture() {}
 
 TestFixture::~TestFixture() {
     TestDriver driver;
+    EXPECT_CALL(driver, send_keyboard_mock(_)).Times(1);
     layer_clear();
     clear_all_keys();
     // Run for a while to make sure all keys are completely released
~

drashna added 4 commits May 19, 2020 01:59
Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.
@drashna drashna force-pushed the tmk_core/layer_state_trash branch from 0356ca7 to 9f30a55 Compare May 19, 2020 09:10
@spidey3
Copy link
Contributor

spidey3 commented May 25, 2020

Just curious, shouldn't this also be done even if bootmagic or magic are not configured (e.g. if using bootmagic lite)?

@drashna
Copy link
Member Author

drashna commented May 25, 2020

Just curious, shouldn't this also be done even if bootmagic or magic are not configured (e.g. if using bootmagic lite)?

Nope.

If bootmagic is set to:

  • full/yes: bootmagic.c is included
  • lite: magic.c is included
  • no (default): magic.c is included

So there is no circumstance at which one or the other isn't included.

The logic for this is here:

# Option modules
BOOTMAGIC_ENABLE ?= no
VALID_MAGIC_TYPES := yes full lite
ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
$(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
endif
ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
TMK_COMMON_DEFS += -DBOOTMAGIC_LITE
TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic_lite.c
TMK_COMMON_DEFS += -DMAGIC_ENABLE
TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
else
TMK_COMMON_DEFS += -DBOOTMAGIC_ENABLE
TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic.c
endif
else
TMK_COMMON_DEFS += -DMAGIC_ENABLE
TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
endif

@spidey3
Copy link
Contributor

spidey3 commented May 25, 2020

So there is no circumstance at which one or the other isn't included.

I stand corrected!
Hadn't noticed that magic.c would be included in all circumstances.

@drashna
Copy link
Member Author

drashna commented May 27, 2020

No worries! There are a lot of things that are hidden and obfuscated, if you haven't dug deep into the bowels of the code. That's part of why I posted the code reference, since learning more == good. :)

@drashna drashna removed the on hold label May 27, 2020
@stale
Copy link

stale bot commented Jul 11, 2020

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@stale stale bot removed the awaiting changes label Jul 16, 2020
@tzarc tzarc changed the base branch from master to develop July 25, 2020 23:04
@tzarc
Copy link
Member

tzarc commented Jul 25, 2020

Retargeted develop due to core changes.
Are we waiting on anything else other than another review?

@drashna
Copy link
Member Author

drashna commented Jul 26, 2020

Are we waiting on anything else other than another review?

Nope. Should be ready to merge.

@tzarc tzarc merged commit ed8fc02 into qmk:develop Jul 27, 2020
@drashna drashna deleted the tmk_core/layer_state_trash branch July 28, 2020 05:48
noroadsleft pushed a commit that referenced this pull request Jul 31, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
noroadsleft pushed a commit that referenced this pull request Aug 11, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
noroadsleft pushed a commit that referenced this pull request Aug 27, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
noroadsleft pushed a commit that referenced this pull request Aug 29, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
nicocesar pushed a commit to nicocesar/qmk_firmware that referenced this pull request Sep 6, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
drashna added a commit to zsa/qmk_firmware that referenced this pull request Sep 30, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
kjganz pushed a commit to kjganz/qmk_firmware that referenced this pull request Oct 28, 2020
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
* Initialize Layer State on startup

Right now, on startup, the default layer state gets called and set, triggering the callback functions for the default layer state. However, the normal layer state never actually gets initialized.  It's set to 0 directly, by default, but the callback functions are never actually called.  This creates some inconsistency in the behavior for end users.  This adds a simple "clear" that triggers the callback on startup.  This should produce more consisten behavior between the two functions and layer masks.

* Stupid hack

* Fix type casting?

* Fix compile issues with magic is disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants