cdk_binding(3)
π cdk_binding(3) β Cdk character binding capabilities π
okay bestie, welcome to cdk_binding(3), aka the page where Cdk learns to let you decide which keys do what. no cap, this one's a banger. β¨
π NAME π
cdk_binding β Cdk character binding capabilities π¦
β¨ SYNOPSIS β¨
cc [ flag ... ] file ... -lcdk [ library ... ]
#include <cdk.h>
void bindCDKObject (
EObjectType cdkType,
void *object,
chtype key,
BINDFN function,
void *data);
int checkCDKObjectBind (
EObjectType cdkType,
void *object,
chtype key);
void cleanCDKObjectBindings (
EObjectType cdkType,
void *object);
bool isCDKObjectBind (
EObjectType cdkType,
void *object,
chtype key);
void unbindCDKObject (
EObjectType cdkType,
void *object,
chtype key);
int getcCDKObject (
CDKOBJS *object);
int getchCDKObject (
CDKOBJS *object,
boolean *functionKey);
πΈ DESCRIPTION πΈ
so here's the tea, bestie: Cdk has the ability to create user definable key bindings. literally, you get to pick the keys. and that ability makes Cdk way more dynamic and usable for a wide variety of tasks β it's giving flexible, it's giving main character energy π
the next section outlines the binding functions, their use, and their purpose. every single one of them. no skipping. periodt. π
π§ bindCDKObject
creates a key binding between a specific Cdk widget (that's the object) and a given key.
the parameter cdkType is of type EObjectType, which is one of the following values β here's the whole roster, and yes we're listing every single one because they're all iconic in their own way:
EObjectType_Value/Corresponding_Widget/Widget_Manual_Pageβ that's the three columns, bestie πvALPHALISTβ Alphalist Widget βcdk_alphalist(3)vBUTTONβ Button Widget βcdk_button(3)vBUTTONBOXβ Buttonbox Widget βcdk_buttonbox(3)vCALENDARβ Calendar Widget βcdk_calendar(3)vDIALOGβ Dialog Widget βcdk_dialog(3)vDSCALEβ DoubleFloat Widget βcdk_dscale(3)vENTRYβ Entry Widget βcdk_entry(3)vFSCALEβ Floating Scale Widget βcdk_fscale(3)vFSELECTβ File Selector Widget βcdk_fselect(3)vFSLIDERβ Floating Slider Widget βcdk_fslider(3)vGRAPHβ Graph Widget βcdk_graph(3)vHISTOGRAMβ Histogram Widget βcdk_histogram(3)vITEMLISTβ Item List Widget βcdk_itemlist(3)vLABELβ Label Widget βcdk_label(3)vMARQUEEβ Marquee Widget βcdk_marquee(3)vMATRIXβ Matrix Widget βcdk_matrix(3)vMENTRYβ Multiple Line Entry Widget βcdk_mentry(3)vMENUβ Menu Widget βcdk_menu(3)vRADIOβ Radio List Widget βcdk_radio(3)vSCALEβ Integer Scale Widget βcdk_scale(3)vSCROLLβ Scrolling List Widget βcdk_scroll(3)vSELECTIONβ Selection List Widget βcdk_selection(3)vSLIDERβ Slider Widget βcdk_slider(3)vSWINDOWβ Scrolling Window Widget βcdk_swindow(3)vTEMPLATEβ Template Entry Widget βcdk_template(3)vUSCALEβ Unsigned Scale Widget βcdk_uscale(3)vUSLIDERβ Unsigned Slider Widget βcdk_uslider(3)vVIEWERβ Viewer Widget βcdk_viewer(3)
okay so now the parameters:
- the parameter function is the callback function π«Ά
- the parameter data points to data passed to the callback function
- the parameter key is the key hit which triggered this callback
π checkCDKObjectBind
check to see if a binding for the given key exists.
- if it does, Cdk runs the associated command and returns its value β normally
TRUE⨠- if no binding exists, return
FALSE
the widgets which accept input β e.g., via "inject" methods β use this to check if the injected character is bound to a function. if that returns TRUE, the widget may update its exitType value: if earlyExit value is set (not equal to vNEVER_ACTIVATED), the widget sets exitType to that value. iykyk π
π§Ό cleanCDKObjectBindings
removes all user defined key bindings from the given widget. full reset, fresh start, no baggage. it's giving healing era π¦
π©΅ isCDKObjectBind
check to see if a binding for the given key exists.
- if it does, return
TRUE - if no binding exists, return
FALSE
simple as that, bestie. a vibe check for your key bindings fr fr.
βοΈ unbindCDKObject
removes a specific binding to an object. the parameters are the same as for bindCDKObject. not me breaking up with one single key binding π₯²
β οΈ getcCDKObject
reads a keycode from the given widget.
bestie, this one is deprecated. use getchCDKObject instead. π we're listing it because the page lists it, not because we endorse it.
π getchCDKObject
reads a keycode from the given widget, and sets a flag via the functionKey parameter to indicate if the result is a function key.
the functionKey parameter may be null β the keycode is returned whether or not the flag can be set. she's flexible like that π
now, the important bit: if the keycode has been bound to the special function getcCDKBind, then it will be translated to the value which was given for the binding data. otherwise, a few special cases are performed:
CTRL-AβKEY_HOMECTRL-BβKEY_LEFTCTRL-EβKEY_ENDCTRL-FβKEY_RIGHTCTRL-NβtabCTRL-PβKEY_BTABDELβKEY_DCbackspaceβKEY_BACKSPACEcarriage returnβKEY_ENTERnewlineβKEY_ENTER
(that's the Key / Result table up there, faithfully reproduced, because we keep every detail around here π)
and the closing note, which is honestly so satisfying: All of the widgets use getchCDKObject internally for consistency. π consistency is the moment, bestie. every single widget, same path, same vibe.
π EXAMPLES π
ok so to actually show you how these key bindings work in the wild, here's a whole lil dialog box widget β every single button gets its own help popup π«Ά. This code segment builds a dialog box plus a callback function named dialogHelpCB.
the icon of the show is right here, bestie:
bindCDKObject (vDIALOG, question, '?', dialogHelpCB, 0);
that one line is literally the whole vibe β press ? inside the dialog and boom, your help callback fires. π
#include <cdk.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName="bind_ex";
#endif
static int dialogHelpCB (EObjectType cdktype GCC_UNUSED, void *object, void *clientData GCC_UNUSED, chtype key GCC_UNUSED)
{
CDKDIALOG *dialog = (CDKDIALOG *)object;
char *mesg[5];
/* Check which button we are on. */
if (dialog->currentButton == 0)
{
mesg[0] = "<C></U>Help for </U>Who<!U>.";
mesg[1] = "<C>When this button is picked the name of the current";
mesg[2] = "<C>user is displayed on the screen in a popup window.";
popupLabel (ScreenOf(dialog), mesg, 3);
}
else if (dialog->currentButton == 1)
{
mesg[0] = "<C></U>Help for </U>Time<!U>.";
mesg[1] = "<C>When this button is picked the current time is";
mesg[2] = "<C>displayed on the screen in a popup window.";
popupLabel (ScreenOf(dialog), mesg, 3);
}
else if (dialog->currentButton == 2)
{
mesg[0] = "<C></U>Help for </U>Date<!U>.";
mesg[1] = "<C>When this button is picked the current date is";
mesg[2] = "<C>displayed on the screen in a popup window.";
popupLabel (ScreenOf(dialog), mesg, 3);
}
else if (dialog->currentButton == 3)
{
mesg[0] = "<C></U>Help for </U>Quit<!U>.";
mesg[1] = "<C>When this button is picked the dialog box is exited.";
popupLabel (ScreenOf(dialog), mesg, 2);
}
return (FALSE);
}
int main (void)
{
/* Declare variables. */
CDKSCREEN *cdkscreen;
CDKDIALOG *question;
char *buttons[40];
char *message[40], *info[5], *loginName;
char temp[256];
int selection;
time_t clck;
struct tm *currentTime;
cdkscreen = initCDKScreen (NULL);
/* Start color. */
initCDKColor();
/* Set up the dialog box. */
message[0] = "<C></U>Simple Command Interface";
message[1] = "Pick the command you wish to run.";
message[2] = "<C>Press </R>?<!R> for help.";
buttons[0] = "Who";
buttons[1] = "Time";
buttons[2] = "Date";
buttons[3] = "Quit";
/* Create the dialog box. */
question = newCDKDialog (cdkscreen, CENTER, CENTER,
message, 3, buttons, 4, A_REVERSE,
TRUE, TRUE, FALSE);
/* Check if we got a null value back. */
if (question == (CDKDIALOG *)0)
{
destroyCDKScreen (cdkscreen);
/* End curses... */
endCDK();
/* Spit out a message. */
printf ("Oops. Can't seem to create the dialog box. Is the window too small?\n");
exit (1);
}
/* Create the key binding. */
bindCDKObject (vDIALOG, question, '?', dialogHelpCB, 0);
/* Activate the dialog box. */
selection = 0;
while (selection != 3)
{
/* Get the users button selection. */
selection = activateCDKDialog (question, (chtype *)0);
/* Check the results. */
if (selection == 0)
{
/* Get the users login name. */
info[0] = "<C> </U>Login Name<!U> ";
loginName = getlogin();
if (loginName == (char *)0)
{
strcpy (temp, "<C></R>Unknown");
}
else
{
sprintf (temp, "<C><%s>", loginName);
}
info[1] = copyChar (temp);
popupLabel (ScreenOf(question), info, 2);
freeChar (info[1]);
}
else if (selection == 1)
{
/* Print out the time. */
time(&clck);
currentTime = localtime(&clck);
sprintf (temp, "<C>%d:%d:%d", currentTime->tm_hour,
currentTime->tm_min,
currentTime->tm_sec);
info[0] = "<C> </U>Current Time<!U> ";
info[1] = copyChar (temp);
popupLabel (ScreenOf(question), info, 2);
freeChar (info[1]);
}
else if (selection == 2)
{
/* Print out the date. */
time(&clck);
currentTime = localtime(&clck);
sprintf (temp, "<C>%d/%d/%02d", currentTime->tm_mday,
currentTime->tm_mon,
currentTime->tm_year % 100);
info[0] = "<C> </U>Current Date<!U> ";
info[1] = copyChar (temp);
popupLabel (ScreenOf(question), info, 2);
freeChar (info[1]);
}
}
/* Clean up. */
destroyCDKDialog (question);
destroyCDKScreen (cdkscreen);
endCDK();
exit (0);
}
π SEE ALSO π
ok that's the whole page, bestie β you ate it, no crumbs πβ¨. This one came out of the CDK source dated 2025-01-14, and it's page cdk_binding(3) in case you need to cite it. go bind some keys, you main character ππ
π¦ where this page comes from
- debian trixie: libcdk5-dev 5.0.20250116-1 Β· BSD-4-Clause
- fedora 43: cdk 5.0.20251014-1.fc43 Β· X11-distribute-modifications-variant
- fedora 43: cdk 5.0.20251014-1.fc43 Β· X11-distribute-modifications-variant
- fedora 44: cdk 5.0.20251014-3.fc44 Β· X11-distribute-modifications-variant
- fedora 44: cdk 5.0.20251014-3.fc44 Β· X11-distribute-modifications-variant
- nixos 26.05: cdk 5.0-20260119
- nixpkgs unstable: cdk 5.0-20260119
- ubuntu questing: libcdk5-dev 5.0.20250116-1
- ubuntu resolute: libcdk5-dev 5.0.20251014-1 Β· BSD-4-Clause
- ubuntu stonking: libcdk5-dev 5.0.20260119-1 Β· BSD-4-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms