Subversion Repositories Kolibri OS

Rev

Rev 9261 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // Mouse Configuration Utility ver 1.7
  2.  
  3. #define MEMSIZE 4096*11
  4.  
  5. #include "..\lib\strings.h"
  6. #include "..\lib\mem.h"
  7. #include "..\lib\fs.h"
  8. #include "..\lib\gui.h"
  9. #include "..\lib\obj\libini.h"
  10. #include "..\lib\patterns\restart_process.h"
  11.  
  12. // Translatiions
  13. #ifdef LANG_RUS
  14.         ?define WINDOW_TITLE "à®¢¥àª  ¨ ­ áâனª  ¯ à ¬¥â஢ ¬ëè¨"
  15.         ?define CHECK_MOUSE_1 " ¦¬¨â¥ ­  í⮩ ®¡« áâ¨"
  16.         ?define CHECK_MOUSE_2 "¤«ï ¯à®¢¥àª¨ ª­®¯®ª ¬ëè¨"
  17.         ?define POINTER_SPEED "„¥«¨â¥«ì ᪮à®á⨠㪠§ â¥«ï ¬ëè¨"
  18.         ?define ACCELERATION_TEXT "—ã¢á⢨⥫쭮áâì 㪠§ â¥«ï ¬ëè¨"
  19.         ?define DOUBLE_CLICK_TEXT "‡ ¤¥à¦ª  ¤¢®©­®£® ª«¨ª  ¬ëèìî"
  20.         ?define MOUSE_EMULATION "“¯à ¢«¥­¨¥ 㪠§ â¥«¥¬ ¬ëè¨ ç¥à¥§ ª« ¢¨ âãàã (F1)"
  21.         ?define COMMOUSE "‡ £à㧨âì ¤à ©¢¥à ¬ëè¨ ¤«ï COM-¯®àâ  (F2)"
  22.         ?define MADMOUSE "‘ª¢®§­ë¥ ¤«ï ªãàá®à  áâ®à®­ë íªà ­ "
  23.         ?define COMMOUSE_LOADED "'„à ©¢¥à ¤«ï COM ¬ëè¨ ¡ë« § £à㦥­' -O"
  24.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Žáâ ­®¢ª  ¤à ©¢¥à  ­¥¢®§¬®¦­ ' -W"
  25. #else
  26.         ?define WINDOW_TITLE "Mouse testing and configuration"
  27.         ?define CHECK_MOUSE_1 "Click on this area to"
  28.         ?define CHECK_MOUSE_2 "check your mouse buttons"
  29.         ?define POINTER_SPEED "Mouse pointer speed divider"
  30.         ?define ACCELERATION_TEXT "Mouse pointer sensitivity"
  31.         ?define DOUBLE_CLICK_TEXT "Mouse double click delay"
  32.         ?define MOUSE_EMULATION "Enable mouse emulation using keyboard NumPad (F1)"
  33.         ?define COMMOUSE "Load mouse driver for COM-port (F2)"
  34.         ?define MADMOUSE "Through screen sides for pointer"
  35.         ?define COMMOUSE_LOADED "'Driver for COM mouse loaded' -O"
  36.         ?define COMMOUSE_CAN_NOT_UNLOAD "'Driver stop is impossible' -W"
  37. #endif
  38.  
  39. #define FRAME_X 18
  40. #define FRAME_Y 18
  41. :block mouse_frame = { FRAME_X, FRAME_Y, NULL, 130 };
  42. :more_less_box pointer_speed      = { NULL, 0, 64, POINTER_SPEED };
  43. :more_less_box acceleration       = { NULL, 0, 64, ACCELERATION_TEXT };
  44. :more_less_box double_click_delay = { NULL, 0, 999, DOUBLE_CLICK_TEXT, 8 };
  45. :checkbox emulation = { MOUSE_EMULATION, NULL };
  46. :checkbox madmouse = { MADMOUSE, NULL };
  47. :checkbox com_mouse = { COMMOUSE, NULL };
  48.  
  49. char ini_path[] = "/sys/settings/system.ini";
  50. _ini ini_drivers = { #ini_path, "loaded drivers" };
  51. _ini ini_mouse = { #ini_path, "mouse" };
  52.  
  53. void main() {
  54.         proc_info Form;
  55.         int id;
  56.  
  57.         load_dll(libini, #lib_init,1);
  58.  
  59.         LoadCfg();
  60.  
  61.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  62.  
  63.         loop() switch(@WaitEvent())
  64.         {
  65.                 case evMouse:
  66.                                 mouse.get();
  67.                                 IF (mouse_frame.hovered()) DrawMouseImage(mouse.lkm,mouse.pkm,mouse.mkm,mouse.vert);
  68.                                 IF (mouse.click) || (mouse.up) DrawMouseImage(0,0,0,0);
  69.                                 break;
  70.  
  71.                 CASE evButton:
  72.                                 id = @GetButtonID();
  73.                                 IF (1 == id) ExitApp();
  74.                                 else IF (pointer_speed.click(id)) ApplyCfg();
  75.                                 else IF (acceleration.click(id)) ApplyCfg();
  76.                                 else IF (double_click_delay.click(id)) ApplyCfg();
  77.                                 else IF (emulation.click(id)) {
  78.                                         EventClickEmulation();
  79.                                 }
  80.                                 else IF (madmouse.click(id)) {
  81.                                         IF (madmouse.checked == true) RunProgram("/sys/madmouse", 0);
  82.                                         ELSE KillProcessByName("madmouse", SINGLE);
  83.                                         break;
  84.                                 }
  85.                                 else IF (id == com_mouse.id) {
  86.                                         EventClickComMouse();
  87.                                 }
  88.                                 break;
  89.  
  90.                 case evKey:
  91.                                 @GetKeyScancode();
  92.                                 IF (AL == SCAN_CODE_ESC) ExitApp();
  93.                                 IF (AL == SCAN_CODE_F1) {
  94.                                         emulation.click(emulation.id);
  95.                                         EventClickEmulation();
  96.                                 }
  97.                                 IF (AL == SCAN_CODE_F2) EventClickComMouse();
  98.                                 break;
  99.  
  100.                 case evReDraw:
  101.                                 sc.get();
  102.                                 DefineAndDrawWindow(430, 150, 460, 343+skin_h,0x34,sc.work,WINDOW_TITLE,0);
  103.                                 GetProcessInfo(#Form, SelfInfo);
  104.                                 if (Form.status_window&ROLLED_UP) break;
  105.                                 mouse_frame.w = - FRAME_X * 2 + Form.cwidth;
  106.                                 DefineButton(FRAME_X, FRAME_Y, mouse_frame.w,
  107.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  108.                                 WriteText(FRAME_X + 110, FRAME_Y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  109.                                 WriteText(FRAME_X + 110, FRAME_Y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  110.                                 DrawMouseImage(0,0,0,0);
  111.                                 DrawControls();
  112.         }
  113. }
  114.  
  115. :byte panels_img_data[] = FROM "mouse_image.raw";
  116.  
  117. #define red    0xff0000
  118. #define yellow 0xfff600
  119. #define white  0xffffff
  120. #define dgrey  0x2d353d
  121.  
  122. :struct IMG_PAL{ dword back, shad1, contour, left,  right, middle, mwhite; }
  123.          pal = { 0xF0F2F3,0xABB0B2, dgrey,   white, white, dgrey,  white  };
  124.  
  125. void DrawMouseImage(dword l,r,m,v) {
  126.         #define IMG_W 59
  127.         #define IMG_H 100
  128.  
  129.         IF (l) pal.left = red;
  130.         IF (m) pal.middle = red;
  131.         IF (r) pal.right = red;
  132.         IF (v) pal.middle = yellow;
  133.  
  134.         PutPaletteImage(#panels_img_data,IMG_W,IMG_H,18+30,18+16,8,#pal);
  135.         pal.left = pal.right = white;
  136.         pal.middle = dgrey;
  137.         IF (v) {
  138.                 pause(10);
  139.                 DrawMouseImage(l,r,m,0);
  140.         }
  141. }
  142.  
  143. void DrawControls() {
  144.         incn y;
  145.         y.n = FRAME_Y+115;
  146.         pointer_speed.draw(FRAME_X, y.inc(30));
  147.         acceleration.draw(FRAME_X, y.inc(30));
  148.         double_click_delay.draw(FRAME_X, y.inc(30));
  149.         emulation.draw(FRAME_X, y.inc(33));
  150.         com_mouse.draw(FRAME_X, y.inc(27));
  151.         madmouse.draw(FRAME_X, y.inc(27));
  152. }
  153.  
  154. void LoadCfg() {
  155.         acceleration.value = @GetMouseAcceleration();
  156.         pointer_speed.value = @GetMouseSpeed();
  157.         double_click_delay.value = @GetMouseDoubleClickDelay();
  158.         com_mouse.checked = ini_drivers.GetInt("com_mouse", 0);
  159.         madmouse.checked = CheckProcessExists("MADMOUSE");
  160.         emulation.checked = CheckProcessExists("MOUSEMUL");
  161. }
  162.  
  163. void ExitApp() {
  164.         ini_drivers.SetInt("com_mouse", com_mouse.checked);
  165.         ini_mouse.SetInt("speed", pointer_speed.value);
  166.         ini_mouse.SetInt("acceleration", acceleration.value);
  167.         ini_mouse.SetInt("double_click_delay", double_click_delay.value);
  168.         @ExitProcess();
  169. }
  170.  
  171. void ApplyCfg() {
  172.         @SetMouseSpeed(pointer_speed.value);
  173.         @SetMouseAcceleration(acceleration.value);
  174.         @SetMouseDoubleClickDelay(double_click_delay.value);
  175. }
  176.  
  177. void EventClickComMouse()
  178. {
  179.         if (!com_mouse.checked)
  180.         {
  181.                 if (RunProgram("/sys/loaddrv", "COMMOUSE")>=0) {
  182.                         notify(COMMOUSE_LOADED);
  183.                         com_mouse.click(com_mouse.id);
  184.                 } else {
  185.                         notify("'Error running LOADDRV' -E");
  186.                 }
  187.         } else {
  188.                 notify(COMMOUSE_CAN_NOT_UNLOAD);
  189.         }
  190. }
  191.  
  192. void EventClickEmulation()
  193. {
  194.         IF (emulation.checked == true) {
  195.                 RunProgram("/sys/mousemul", 0);
  196.         }       ELSE {
  197.                 KillProcessByName("mousemul", SINGLE);
  198.         }
  199. }
  200.  
  201. stop:
  202.