aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/button-hotplug/src/button-hotplug.c
Commit message (Collapse)AuthorAgeFilesLines
* button-hotplug: add KEY_POWER2 handlingAlan Swanson2019-05-301-0/+1
| | | | | | | | | | | | | | | | For devices such as BTHOMEHUBV5A with both reset and restart buttons, its easily accessible restart button has been assigned to KEY_POWER power script to poweroff preventing accidental (or malicious) factory resets by KEY_RESTART reset script. However an easily accessible button immediately powering off the device is also undesirable. As KEY_RESTART is already used for reset script (and there's no KEY_REBOOT in Linux input events), use KEY_POWER2 for rebooting via new reboot script with 5 second seen delay. Fixes: FS#1965 Signed-off-by: Alan Swanson <reiver@improbability.net> Signed-off-by: Petr Štetiar <ynezz@true.cz> [long line wrap]
* treewide: replace nbd@openwrt.org with nbd@nbd.nameFelix Fietkau2016-06-071-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@nbd.name>
* button-hotplug: remove #ifdef CONFIG_HOTPLUG, it is gone in newer kernelsFelix Fietkau2014-05-231-7/+0
| | | | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org> SVN-Revision: 40839
* gpio-button-hotplug: add wwan buttonHauke Mehrtens2014-01-141-2/+1
| | | | | | | | | | | The wimax key will be used as a generic wwan key starting with Linux 3.13. The brcm47xx target uses this key for the 3g buttons. Also remove the ifdef around KEY_WPS_BUTTON, this is in the kernel for a long time now. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> SVN-Revision: 39290
* button-hotplug: sync list of supported keys with gpio-button-hotplugJohn Crispin2013-11-071-0/+1
| | | | | | Signed-off-by: John Crispin <blogic@openwrt.org> SVN-Revision: 38676
* button-hotplug: Add KEY_POWER handlingJohn Crispin2013-07-041-0/+1
| | | | | | | | | | | | When running OpenWrt within KVM KEY_POWER is generated from the ACPI button driver when restarting or powering down the VM. Extend button-hotplug to allow user space handlers for these events. Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com> Patchwork: http://patchwork.openwrt.org/patch/3799/ SVN-Revision: 37160
* packages: clean up the package folderJohn Crispin2013-06-211-0/+349
Signed-off-by: John Crispin <blogic@openwrt.org> SVN-Revision: 37007
d='n259' href='#n259'>259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
import typing  # noqa
# Low-color themes should ONLY use the standard foreground and background
# colours listed here:
#
# http://urwid.org/manual/displayattributes.html
#


class Palette:
    _fields = [
        'background',
        'title',

        # Status bar & heading
        'heading', 'heading_key', 'heading_inactive',

        # Help
        'key', 'head', 'text',

        # Options
        'option_selected', 'option_active', 'option_active_selected',
        'option_selected_key',

        # List and Connections
        'method',
        'method_get', 'method_post', 'method_delete', 'method_other', 'method_head', 'method_put', 'method_http2_push',
        'scheme_http', 'scheme_https', 'scheme_other',
        'url_punctuation', 'url_domain', 'url_filename', 'url_extension', 'url_query_key', 'url_query_value',
        'content_none', 'content_text', 'content_script', 'content_media', 'content_data', 'content_raw', 'content_other',
        'focus',
        'code_200', 'code_300', 'code_400', 'code_500', 'code_other',
        'error', "warn", "alert",
        'header', 'highlight', 'intercept', 'replay', 'mark',

        # Hex view
        'offset',

        # Grid Editor
        'focusfield', 'focusfield_error', 'field_error', 'editfield',

        # Commander
        'commander_command', 'commander_invalid', 'commander_hint'
    ]
    _fields.extend(['gradient_%02d' % i for i in range(100)])
    high: typing.Optional[typing.Mapping[str, typing.Sequence[str]]] = None

    def palette(self, transparent):
        l = []
        highback, lowback = None, None
        if not transparent:
            if self.high and self.high.get("background"):
                highback = self.high["background"][1]
            lowback = self.low["background"][1]

        for i in self._fields:
            if transparent and i == "background":
                l.append(["background", "default", "default"])
            else:
                v = [i]
                low = list(self.low[i])
                if lowback and low[1] == "default":
                    low[1] = lowback
                v.extend(low)
                if self.high and i in self.high:
                    v.append(None)
                    high = list(self.high[i])
                    if highback and high[1] == "default":
                        high[1] = highback
                    v.extend(high)
                elif highback and self.low[i][1] == "default":
                    high = [None, low[0], highback]
                    v.extend(high)
                l.append(tuple(v))
        return l


def gen_gradient(palette, cols):
    for i in range(100):
        palette['gradient_%02d' % i] = (cols[i * len(cols) // 100], 'default')


def gen_rgb_gradient(palette, cols):
    parts = len(cols) - 1
    for i in range(100):
        p = i / 100
        idx = int(p * parts)
        t0 = cols[idx]
        t1 = cols[idx + 1]
        pp = p * parts % 1
        t = (
            round(t0[0] + (t1[0] - t0[0]) * pp),
            round(t0[1] + (t1[1] - t0[1]) * pp),
            round(t0[2] + (t1[2] - t0[2]) * pp),
        )
        palette['gradient_%02d' % i] = ("#%x%x%x" % t, 'default')


class LowDark(Palette):

    """
        Low-color dark background
    """
    low = dict(
        background = ('white', 'black'),
        title = ('white,bold', 'default'),

        # Status bar & heading
        heading = ('white', 'dark blue'),
        heading_key = ('light cyan', 'dark blue'),
        heading_inactive = ('dark gray', 'light gray'),

        # Help
        key = ('light cyan', 'default'),
        head = ('white,bold', 'default'),
        text = ('light gray', 'default'),

        # Options
        option_selected = ('black', 'light gray'),
        option_selected_key = ('light cyan', 'light gray'),
        option_active = ('light red', 'default'),
        option_active_selected = ('light red', 'light gray'),

        # List and Connections
        method = ('dark cyan', 'default'),
        method_get = ('light green', 'default'),
        method_post = ('brown', 'default'),
        method_delete = ('light red', 'default'),
        method_head = ('dark cyan', 'default'),
        method_put = ('dark red', 'default'),
        method_other = ('dark magenta', 'default'),
        method_http2_push = ('dark gray', 'default'),

        scheme_http = ('dark cyan', 'default'),
        scheme_https = ('dark green', 'default'),
        scheme_other = ('dark magenta', 'default'),

        url_punctuation = ('light gray', 'default'),
        url_domain = ('white', 'default'),
        url_filename = ('dark cyan', 'default'),
        url_extension = ('light gray', 'default'),
        url_query_key = ('white', 'default'),
        url_query_value = ('light gray', 'default'),

        content_none = ('dark gray', 'default'),
        content_text = ('light gray', 'default'),
        content_script = ('dark green', 'default'),
        content_media = ('light blue', 'default'),
        content_data = ('brown', 'default'),
        content_raw = ('dark red', 'default'),
        content_other = ('dark magenta', 'default'),

        focus = ('yellow', 'default'),

        code_200 = ('dark green', 'default'),
        code_300 = ('light blue', 'default'),
        code_400 = ('light red', 'default'),
        code_500 = ('light red', 'default'),
        code_other = ('dark red', 'default'),

        alert = ('light magenta', 'default'),
        warn = ('brown', 'default'),
        error = ('light red', 'default'),

        header = ('dark cyan', 'default'),
        highlight = ('white,bold', 'default'),
        intercept = ('brown', 'default'),
        replay = ('light green', 'default'),
        mark = ('light red', 'default'),

        # Hex view
        offset = ('dark cyan', 'default'),

        # Grid Editor
        focusfield = ('black', 'light gray'),
        focusfield_error = ('dark red', 'light gray'),
        field_error = ('dark red', 'default'),
        editfield = ('white', 'default'),


        commander_command = ('white,bold', 'default'),
        commander_invalid = ('light red', 'default'),
        commander_hint = ('dark gray', 'default'),
    )
    gen_gradient(low, ['light red', 'yellow', 'light green', 'dark green', 'dark cyan', 'dark blue'])


class Dark(LowDark):
    high = dict(
        heading_inactive = ('g58', 'g11'),
        intercept = ('#f60', 'default'),

        option_selected = ('g85', 'g45'),
        option_selected_key = ('light cyan', 'g50'),
        option_active_selected = ('light red', 'g50'),
    )


class LowLight(Palette):

    """
        Low-color light background
    """
    low = dict(
        background = ('black', 'white'),
        title = ('dark magenta', 'default'),

        # Status bar & heading
        heading = ('white', 'black'),
        heading_key = ('dark blue', 'black'),
        heading_inactive = ('black', 'light gray'),

        # Help
        key = ('dark blue', 'default'),
        head = ('black', 'default'),
        text = ('dark gray', 'default'),

        # Options
        option_selected = ('black', 'light gray'),
        option_selected_key = ('dark blue', 'light gray'),
        option_active = ('light red', 'default'),
        option_active_selected = ('light red', 'light gray'),

        # List and Connections
        method = ('dark cyan', 'default'),
        method_get = ('dark green', 'default'),
        method_post = ('brown', 'default'),
        method_head = ('dark cyan', 'default'),
        method_put = ('light red', 'default'),
        method_delete = ('dark red', 'default'),
        method_other = ('light magenta', 'default'),
        method_http2_push = ('light gray', 'default'),

        scheme_http = ('dark cyan', 'default'),
        scheme_https = ('light green', 'default'),
        scheme_other = ('light magenta', 'default'),

        url_punctuation = ('dark gray', 'default'),
        url_domain = ('dark gray', 'default'),
        url_filename = ('black', 'default'),
        url_extension = ('dark gray', 'default'),
        url_query_key = ('light blue', 'default'),
        url_query_value = ('dark blue', 'default'),

        content_none = ('black', 'default'),
        content_text = ('dark gray', 'default'),
        content_script = ('light green', 'default'),
        content_media = ('light blue', 'default'),
        content_data = ('brown', 'default'),
        content_raw = ('light red', 'default'),
        content_other = ('light magenta', 'default'),

        focus = ('black', 'default'),

        code_200 = ('dark green', 'default'),
        code_300 = ('light blue', 'default'),
        code_400 = ('dark red', 'default'),
        code_500 = ('dark red', 'default'),
        code_other = ('light red', 'default'),

        error = ('light red', 'default'),
        warn = ('brown', 'default'),
        alert = ('light magenta', 'default'),

        header = ('dark blue', 'default'),
        highlight = ('black,bold', 'default'),
        intercept = ('brown', 'default'),
        replay = ('dark green', 'default'),
        mark = ('dark red', 'default'),

        # Hex view
        offset = ('dark blue', 'default'),

        # Grid Editor
        focusfield = ('black', 'light gray'),
        focusfield_error = ('dark red', 'light gray'),
        field_error = ('dark red', 'black'),
        editfield = ('black', 'default'),

        commander_command = ('dark magenta', 'default'),
        commander_invalid = ('light red', 'default'),
        commander_hint = ('light gray', 'default'),
    )
    gen_gradient(low, ['light red', 'yellow', 'light green', 'dark green', 'dark cyan', 'dark blue'])


class Light(LowLight):
    high = dict(
        background = ('black', 'g100'),
        heading = ('g99', '#08f'),
        heading_key = ('#0ff,bold', '#08f'),
        heading_inactive = ('g35', 'g85'),
        replay = ('#0a0,bold', 'default'),

        option_selected = ('black', 'g85'),
        option_selected_key = ('dark blue', 'g85'),
        option_active_selected = ('light red', 'g85'),
    )


# Solarized palette in Urwid-style terminal high-colour offsets
# See: http://ethanschoonover.com/solarized
sol_base03 = "h234"
sol_base02 = "h235"
sol_base01 = "h240"
sol_base00 = "h241"
sol_base0 = "h244"
sol_base1 = "h245"
sol_base2 = "h254"
sol_base3 = "h230"
sol_yellow = "h136"
sol_orange = "h166"
sol_red = "h160"
sol_magenta = "h125"
sol_violet = "h61"
sol_blue = "h33"
sol_cyan = "h37"
sol_green = "h64"


class SolarizedLight(LowLight):
    high = dict(
        background = (sol_base00, sol_base3),
        title = (sol_cyan, 'default'),
        text = (sol_base00, 'default'),

        # Status bar & heading
        heading = (sol_base2, sol_base02),
        heading_key = (sol_blue, sol_base03),
        heading_inactive = (sol_base03, sol_base1),

        # Help
        key = (sol_blue, 'default',),
        head = (sol_base00, 'default'),

        # Options
        option_selected = (sol_base03, sol_base2),
        option_selected_key = (sol_blue, sol_base2),
        option_active = (sol_orange, 'default'),
        option_active_selected = (sol_orange, sol_base2),

        # List and Connections

        method = ('dark cyan', 'default'),
        method_get = (sol_green, 'default'),
        method_post = (sol_orange, 'default'),
        method_head = (sol_cyan, 'default'),
        method_put = (sol_red, 'default'),
        method_delete = (sol_red, 'default'),
        method_other = (sol_magenta, 'default'),
        method_http2_push = ('light gray', 'default'),

        scheme_http = (sol_cyan, 'default'),
        scheme_https = ('light green', 'default'),
        scheme_other = ('light magenta', 'default'),

        url_punctuation = ('dark gray', 'default'),
        url_domain = ('dark gray', 'default'),
        url_filename = ('black', 'default'),
        url_extension = ('dark gray', 'default'),
        url_query_key = (sol_blue, 'default'),
        url_query_value = ('dark blue', 'default'),

        focus = (sol_base01, 'default'),

        code_200 = (sol_green, 'default'),
        code_300 = (sol_blue, 'default'),
        code_400 = (sol_orange, 'default',),
        code_500 = (sol_red, 'default'),
        code_other = (sol_magenta, 'default'),

        error = (sol_red, 'default'),
        warn = (sol_orange, 'default'),
        alert = (sol_magenta, 'default'),

        header = (sol_blue, 'default'),
        highlight = (sol_base01, 'default'),
        intercept = (sol_red, 'default',),
        replay = (sol_green, 'default',),

        # Hex view
        offset = (sol_cyan, 'default'),

        # Grid Editor
        focusfield = (sol_base00, sol_base2),
        focusfield_error = (sol_red, sol_base2),
        field_error = (sol_red, 'default'),
        editfield = (sol_base01, 'default'),

        commander_command = (sol_cyan, 'default'),
        commander_invalid = (sol_orange, 'default'),
        commander_hint = (sol_base1, 'default'),
    )


class SolarizedDark(LowDark):
    high = dict(
        background = (sol_base2, sol_base03),
        title = (sol_blue, 'default'),
        text = (sol_base1, 'default'),

        # Status bar & heading
        heading = (sol_base2, sol_base01),
        heading_key = (sol_blue + ",bold", sol_base01),
        heading_inactive = (sol_base1, sol_base02),

        # Help
        key = (sol_blue, 'default',),
        head = (sol_base2, 'default'),

        # Options
        option_selected = (sol_base03, sol_base00),
        option_selected_key = (sol_blue, sol_base00),
        option_active = (sol_orange, 'default'),
        option_active_selected = (sol_orange, sol_base00),

        # List and Connections
        focus = (sol_base1, 'default'),

        method = (sol_cyan, 'default'),
        method_get = (sol_green, 'default'),
        method_post = (sol_orange, 'default'),
        method_delete = (sol_red, 'default'),
        method_head = (sol_cyan, 'default'),
        method_put = (sol_red, 'default'),
        method_other = (sol_magenta, 'default'),
        method_http2_push = (sol_base01, 'default'),

        url_punctuation = ('h242', 'default'),
        url_domain = ('h252', 'default'),
        url_filename = ('h132', 'default'),
        url_extension = ('h96', 'default'),
        url_query_key = ('h37', 'default'),
        url_query_value = ('h30', 'default'),

        content_none = (sol_base01, 'default'),
        content_text = (sol_base1, 'default'),
        content_media = (sol_blue, 'default'),

        code_200 = (sol_green, 'default'),
        code_300 = (sol_blue, 'default'),
        code_400 = (sol_orange, 'default',),
        code_500 = (sol_red, 'default'),
        code_other = (sol_magenta, 'default'),

        error = (sol_red, 'default'),
        warn = (sol_orange, 'default'),
        alert = (sol_magenta, 'default'),

        header = (sol_blue, 'default'),
        highlight = (sol_base01, 'default'),
        intercept = (sol_red, 'default',),
        replay = (sol_green, 'default',),

        # Hex view
        offset = (sol_cyan, 'default'),

        # Grid Editor
        focusfield = (sol_base0, sol_base02),
        focusfield_error = (sol_red, sol_base02),
        field_error = (sol_red, 'default'),
        editfield = (sol_base1, 'default'),

        commander_command = (sol_blue, 'default'),
        commander_invalid = (sol_orange, 'default'),
        commander_hint = (sol_base00, 'default'),
    )
    gen_rgb_gradient(high, [(15, 0, 0), (15, 15, 0), (0, 15, 0), (0, 15, 15), (0, 0, 15)])


DEFAULT = "dark"
palettes = {
    "lowlight": LowLight(),
    "lowdark": LowDark(),
    "light": Light(),
    "dark": Dark(),
    "solarized_light": SolarizedLight(),
    "solarized_dark": SolarizedDark(),
}