2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 NoCapsLock commodity -- Renders the CAPS LOCK key ineffective
8 /******************************************************************************
24 Renders the CAPS LOCK key ineffective.
28 CX_PRIORITY -- The priority of the commodity
44 05.03.2000 SDuvan implemented
46 ******************************************************************************/
48 #include <aros/symbolsets.h>
49 #include <intuition/intuition.h>
50 #include <intuition/intuitionbase.h>
51 #include <libraries/commodities.h>
52 #include <libraries/locale.h>
53 #include <proto/exec.h>
54 #include <proto/dos.h>
55 #include <proto/intuition.h>
56 #include <proto/layers.h>
57 #include <proto/commodities.h>
58 #include <proto/locale.h>
59 #include <proto/alib.h>
65 #include <aros/debug.h>
70 #define CATALOG_NAME "System/Tools/Commodities.catalog"
71 #define CATALOG_VERSION 3
74 /***************************************************************************/
76 UBYTE version
[] = "$VER: NoCapsLock 1.1 (15.04.2006)";
78 #define ARG_TEMPLATE "CX_PRIORITY=PRI/N/K"
84 static struct NewBroker nb
=
90 NBU_NOTIFY
| NBU_UNIQUE
,
98 typedef struct _APState
101 struct MsgPort
*as_msgPort
;
105 static struct Catalog
*catalog
;
107 /***************************************************************************/
109 static void freeResources(APState
*as
);
110 static BOOL
initiate(int argc
, char **argv
, APState
*as
);
111 static void killCapsLockCustomFunc(CxMsg
*msg
, CxObj
*co
);
112 static CONST_STRPTR
_(ULONG id
);
113 static BOOL
Locale_Initialize(VOID
);
114 static VOID
Locale_Deinitialize(VOID
);
115 static void showSimpleMessage(CONST_STRPTR msgString
);
117 /***************************************************************************/
119 static CONST_STRPTR
_(ULONG id
)
121 if (LocaleBase
!= NULL
&& catalog
!= NULL
)
123 return GetCatalogStr(catalog
, id
, CatCompArray
[id
].cca_Str
);
127 return CatCompArray
[id
].cca_Str
;
131 /***************************************************************************/
133 static BOOL
Locale_Initialize(VOID
)
135 if (LocaleBase
!= NULL
)
137 catalog
= OpenCatalog
139 NULL
, CATALOG_NAME
, OC_Version
, CATALOG_VERSION
, TAG_DONE
150 /************************************************************************************/
152 static VOID
Locale_Deinitialize(VOID
)
154 if(LocaleBase
!= NULL
&& catalog
!= NULL
) CloseCatalog(catalog
);
157 /************************************************************************************/
159 static void showSimpleMessage(CONST_STRPTR msgString
)
161 struct EasyStruct easyStruct
;
163 easyStruct
.es_StructSize
= sizeof(easyStruct
);
164 easyStruct
.es_Flags
= 0;
165 easyStruct
.es_Title
= _(MSG_NOCAPSLOCK_CXNAME
);
166 easyStruct
.es_TextFormat
= msgString
;
167 easyStruct
.es_GadgetFormat
= _(MSG_OK
);
169 if (IntuitionBase
!= NULL
&& !Cli() )
171 EasyRequestArgs(NULL
, &easyStruct
, NULL
, NULL
);
179 /***************************************************************************/
181 static BOOL
initiate(int argc
, char **argv
, APState
*as
)
183 CxObj
*customObj
, *filterObj
;
185 memset(as
, 0, sizeof(APState
));
190 IPTR
*args
[] = { NULL
};
192 rda
= ReadArgs(ARG_TEMPLATE
, (IPTR
*)args
, NULL
);
196 if (args
[ARG_PRI
] != NULL
)
198 nb
.nb_Pri
= (BYTE
)(*args
[ARG_PRI
]);
206 UBYTE
**array
= ArgArrayInit(argc
, (UBYTE
**)argv
);
208 nb
.nb_Pri
= ArgInt(array
, "CX_PRIORITY", 0);
212 nb
.nb_Name
= _(MSG_NOCAPSLOCK_CXNAME
);
213 nb
.nb_Title
= _(MSG_NOCAPSLOCK_CXTITLE
);
214 nb
.nb_Descr
= _(MSG_NOCAPSLOCK_CXDESCR
);
216 as
->as_msgPort
= CreateMsgPort();
218 if (as
->as_msgPort
== NULL
)
220 showSimpleMessage(_(MSG_CANT_CREATE_MSGPORT
));
225 nb
.nb_Port
= as
->as_msgPort
;
227 as
->as_broker
= CxBroker(&nb
, 0);
229 if (as
->as_broker
== NULL
)
234 filterObj
= CxFilter(NULL
);
235 if (filterObj
== NULL
)
237 showSimpleMessage(_(MSG_CANT_CREATE_CUSTOM
));
249 IEQUALIFIER_CAPSLOCK
,
250 IEQUALIFIER_CAPSLOCK
,
254 SetFilterIX(filterObj
, &ix
);
255 AttachCxObj(as
->as_broker
, filterObj
);
259 customObj
= CxCustom(killCapsLockCustomFunc
, 0);
261 if (customObj
== NULL
)
263 showSimpleMessage(_(MSG_CANT_CREATE_CUSTOM
));
268 AttachCxObj(filterObj
, customObj
);
269 ActivateCxObj(as
->as_broker
, TRUE
);
274 /***************************************************************************/
276 static void freeResources(APState
*as
)
282 if (as
->as_broker
!= NULL
)
284 DeleteCxObjAll(as
->as_broker
);
288 if (as
->as_msgPort
!= NULL
)
290 while ((cxm
= GetMsg(as
->as_msgPort
)))
295 DeleteMsgPort(as
->as_msgPort
);
299 /***************************************************************************/
301 /* Our CxCustom() function that is invoked everytime an imputevent is
302 routed to our broker */
303 static void killCapsLockCustomFunc(CxMsg
*msg
, CxObj
*co
)
305 struct InputEvent
*ie
= (struct InputEvent
*)CxMsgData(msg
);
307 ie
->ie_Qualifier
&= ~IEQUALIFIER_CAPSLOCK
;
310 /***************************************************************************/
312 /* React on command messages sent by commodities.library */
313 static void handleCx(APState
*as
)
321 signals
= Wait((1 << nb
.nb_Port
->mp_SigBit
) | SIGBREAKF_CTRL_C
);
323 if (signals
& (1 << nb
.nb_Port
->mp_SigBit
))
325 while ((msg
= (CxMsg
*)GetMsg(as
->as_msgPort
)))
327 switch (CxMsgType(msg
))
330 switch (CxMsgID(msg
))
333 ActivateCxObj(as
->as_broker
, FALSE
);
337 ActivateCxObj(as
->as_broker
, TRUE
);
341 /* Running the program twice <=> quit */
348 } /* switch(CxMsgID(msg)) */
351 } /* switch (CxMsgType(msg))*/
353 ReplyMsg((struct Message
*)msg
);
355 } /* while((msg = (CxMsg *)GetMsg(cs->cs_msgPort))) */
358 if (signals
& SIGBREAKF_CTRL_C
)
363 } /* while (!quit) */
366 /***************************************************************************/
368 int main(int argc
, char **argv
)
371 int error
= RETURN_OK
;
373 if (initiate(argc
, argv
, &aState
))
382 freeResources(&aState
);
387 /***************************************************************************/
389 ADD2INIT(Locale_Initialize
, 90);
390 ADD2EXIT(Locale_Deinitialize
, 90);