forked from AeroNotix/slim-git
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix logic for numlock and update coding style (#16536)
The problem from which Numlock is set to Off when setOn is called. Signed-off-by: Nobuhiro Iwamatsu <[email protected]>
- Loading branch information
iwamatsu
committed
Feb 13, 2012
1 parent
3dfcdd8
commit 0333c59
Showing
3 changed files
with
30 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* SLiM - Simple Login Manager | ||
Copyright (C) 2004-06 Simone Rota <[email protected]> | ||
Copyright (C) 2004-06 Johannes Winkelmann <[email protected]> | ||
Copyright (C) 2012 Nobuhiro Iwamatsu <[email protected]> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -22,6 +23,7 @@ int NumLock::xkb_init(Display* dpy) { | |
int xkb_opcode, xkb_event, xkb_error; | ||
int xkb_lmaj = XkbMajorVersion; | ||
int xkb_lmin = XkbMinorVersion; | ||
|
||
return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin ) | ||
&& XkbQueryExtension( dpy, &xkb_opcode, &xkb_event, &xkb_error, | ||
&xkb_lmaj, &xkb_lmin ); | ||
|
@@ -30,7 +32,8 @@ int NumLock::xkb_init(Display* dpy) { | |
unsigned int NumLock::xkb_mask_modifier( XkbDescPtr xkb, const char *name ) { | ||
int i; | ||
if( !xkb || !xkb->names ) | ||
return 0; | ||
return 0; | ||
|
||
for( i = 0; i < XkbNumVirtualMods; i++ ) { | ||
char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] ); | ||
if( modStr != NULL && strcmp(name, modStr) == 0 ) { | ||
|
@@ -44,39 +47,39 @@ unsigned int NumLock::xkb_mask_modifier( XkbDescPtr xkb, const char *name ) { | |
|
||
unsigned int NumLock::xkb_numlock_mask(Display* dpy) { | ||
XkbDescPtr xkb; | ||
if(( xkb = XkbGetKeyboard( dpy, XkbAllComponentsMask, XkbUseCoreKbd )) != NULL ) { | ||
|
||
xkb = XkbGetKeyboard( dpy, XkbAllComponentsMask, XkbUseCoreKbd ); | ||
if( xkb != NULL ) { | ||
unsigned int mask = xkb_mask_modifier( xkb, "NumLock" ); | ||
XkbFreeKeyboard( xkb, 0, True ); | ||
return mask; | ||
} | ||
return 0; | ||
} | ||
void NumLock::setOn() { | ||
|
||
void NumLock::control_numlock(Display *dpy, bool flag) { | ||
unsigned int mask; | ||
Display* dpy = XOpenDisplay( NULL ); | ||
if( !xkb_init(dpy)) | ||
return; | ||
mask = xkb_numlock_mask(dpy); | ||
if( mask == 0 ) | ||
return; | ||
XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask); | ||
XCloseDisplay( dpy ); | ||
} | ||
|
||
void NumLock::setOff() { | ||
unsigned int mask; | ||
Display* dpy = XOpenDisplay( NULL ); | ||
if( !xkb_init(dpy)) | ||
if( !xkb_init(dpy) ) | ||
return; | ||
|
||
mask = xkb_numlock_mask(dpy); | ||
if( mask == 0 ) | ||
return; | ||
XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, 0); | ||
XCloseDisplay( dpy ); | ||
|
||
if( flag == true ) | ||
XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, 0); | ||
else | ||
XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask); | ||
} | ||
|
||
void NumLock::setOn(Display *dpy) { | ||
control_numlock(dpy, true); | ||
} | ||
|
||
void NumLock::setOff(Display *dpy) { | ||
control_numlock(dpy, false); | ||
} | ||
|
||
|
||
|
||
/* | ||
Copyright (C) 2000-2001 Lubos Lunak <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* SLiM - Simple Login Manager | ||
Copyright (C) 2004-06 Simone Rota <[email protected]> | ||
Copyright (C) 2004-06 Johannes Winkelmann <[email protected]> | ||
Copyright (C) 2012 Nobuhiro Iwamatsu <[email protected]> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -19,13 +20,14 @@ class NumLock { | |
|
||
public: | ||
NumLock(); | ||
static void setOn(); | ||
static void setOff(); | ||
static void setOn(Display *dpy); | ||
static void setOff(Display *dpy); | ||
|
||
private: | ||
static int xkb_init(Display* dpy); | ||
static unsigned int xkb_mask_modifier( XkbDescPtr xkb, const char *name ); | ||
static unsigned int xkb_numlock_mask(Display* dpy); | ||
static void control_numlock(Display *dpy, bool flag); | ||
}; | ||
|
||
#endif |