SYSMON_PSWITCH(9)

πŸ“¦ version 11.0, in nixpkgs unstable

🌸 NAME 🌸

okay bestie, this is SYSMON_PSWITCH(9) from the Kernel Developer's Manual, and the name says it all: sysmon_pswitch is literally the framework for power switches ✨. That’s the whole vibe. πŸ’…

✨ SYNOPSIS ✨

#include <dev/sysmon/sysmonvar.h>

int
sysmon_pswitch_register(struct sysmon_pswitch *smpsw);

void
sysmon_pswitch_unregister(struct sysmon_pswitch *smpsw);

void
sysmon_pswitch_event(struct sysmon_pswitch *smpsw, int event);

πŸ’… DESCRIPTION πŸ’…

the machine-independent sysmon_pswitch gives you a framework for power management. heads up though: the interface has been largely superseded by the pmf(9) framework, but sysmon_pswitch is still used to manage power switches, plus related mechanical adapters and buttons. all of that is encapsulated in this struct 🫢:

struct sysmon_pswitch {
        const char *smpsw_name;         /* power switch name */
        int smpsw_type;                 /* power switch type */

        LIST_ENTRY(sysmon_pswitch) smpsw_list;
};

Unsurprisingly, smpsw_name specifies the name of the power switch and smpsw_type defines the type of it. The following types are defined:

  • PSWITCH_TYPE_POWER
  • PSWITCH_TYPE_SLEEP
  • PSWITCH_TYPE_LID
  • PSWITCH_TYPE_RESET
  • PSWITCH_TYPE_ACADAPTER
  • PSWITCH_TYPE_HOTKEY
  • PSWITCH_TYPE_RADIO

If the type is PSWITCH_TYPE_HOTKEY, there are few predefined names that can be used for smpsw_name:

  • PSWITCH_HK_DISPLAY_CYCLE β€” display-cycle
  • PSWITCH_HK_LOCK_SCREEN β€” lock-screen
  • PSWITCH_HK_BATTERY_INFO β€” battery-info
  • PSWITCH_HK_EJECT_BUTTON β€” eject-button
  • PSWITCH_HK_ZOOM_BUTTON β€” zoom-button
  • PSWITCH_HK_VENDOR_BUTTON β€” vendor-button

Once a power switch event has been proceeded, sysmon_pswitch will inform the user space powerd(8), which will possibly execute a script matching the type of the power switch. πŸ‘‘

🫢 FUNCTIONS 🫢

After the sysmon_pswitch structure has been initialized, a new power switch device can be registered by using sysmon_pswitch_register(). The device can be detached from the framework by sysmon_pswitch_unregister().

The sysmon_pswitch_event() is used to signal a new power switch event. There are two possibilities for the value of event:

  • PSWITCH_EVENT_PRESSED β€” A button has been pressed, the lid has been closed, the AC adapter is off, etc.
  • PSWITCH_EVENT_RELEASED β€” A button has been released, the lid is open, the AC adapter is on, etc.

The corresponding events in powerd(8) are pressed and released.

πŸ‘€ SEE ALSO πŸ‘€

πŸ’– AUTHORS πŸ’–

Jason R. Thorpe <thorpej@NetBSD.org> β€” iconic. πŸ‘‘


okay bye bestie β€” this page is from the Debian edition, dated January 6, 2015, and it’s SYSMON_PSWITCH(9). mwah πŸ’‹

πŸ“¦ where this page comes from