Subversion Repositories Kolibri OS

Rev

Rev 8946 | Rev 9261 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // Mouse Configuration Utility ver 1.62
  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 "“¯à ¢«¥­¨¥ 㪠§ â¥«¥¬ ¬ëè¨ ç¥à¥§ ª« ¢¨ âãàã"
  21.         ?define MADMOUSE "‘ª¢®§­ë¥ ¤«ï ªãàá®à  áâ®à®­ë íªà ­ "
  22.         ?define COMMOUSE "‡ £à㧨âì ¤à ©¢¥à ¬ëè¨ ¤«ï COM-¯®àâ  (F10)"
  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"
  33.         ?define MADMOUSE "Through screen sides for pointer"
  34.         ?define COMMOUSE "Load mouse driver for COM-port (F10)"
  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.                                         IF (emulation.checked == true) RunProgram("/sys/mousemul", 0);
  79.                                         ELSE KillProcessByName("mousemul", SINGLE);
  80.                                         break;
  81.                                 }
  82.                                 else IF (madmouse.click(id)) {                                         
  83.                                         IF (madmouse.checked == true) RunProgram("/sys/madmouse", 0);
  84.                                         ELSE KillProcessByName("madmouse", SINGLE);
  85.                                         break;
  86.                                 }
  87.                                 else IF (id == com_mouse.id) {
  88.                                         EventClickComMouse();
  89.                                 }
  90.                                 break;
  91.  
  92.                 case evKey:
  93.                                 @GetKeyScancode();
  94.                                 IF (AL == SCAN_CODE_ESC) ExitApp();
  95.                                 IF (AL == SCAN_CODE_F10) EventClickComMouse();
  96.                                 break;
  97.                        
  98.                 case evReDraw:
  99.                                 sc.get();
  100.                                 DefineAndDrawWindow(430, 150, 424, 343+skin_height,0x34,sc.work,WINDOW_TITLE,0);
  101.                                 GetProcessInfo(#Form, SelfInfo);
  102.                                 if (Form.status_window&ROLLED_UP) break;
  103.                                 mouse_frame.w = - FRAME_X * 2 + Form.cwidth;
  104.                                 DefineButton(FRAME_X, FRAME_Y, mouse_frame.w,
  105.                                         mouse_frame.h, 99+BT_NOFRAME, 0xF0F2F3); //needed to handle mouse_up and refresh mouse image
  106.                                 WriteText(FRAME_X + 110, FRAME_Y + 25, 0x90, 0x2C343C, CHECK_MOUSE_1);
  107.                                 WriteText(FRAME_X + 110, FRAME_Y + 45, 0x90, 0x2C343C, CHECK_MOUSE_2);
  108.                                 DrawMouseImage(0,0,0,0);
  109.                                 DrawControls();
  110.         }
  111. }
  112.  
  113. :byte panels_img_data[] = FROM "mouse_image.raw";
  114.  
  115. #define red    0xff0000
  116. #define yellow 0xfff600
  117. #define white  0xffffff
  118. #define dgrey  0x2d353d
  119.  
  120. :struct IMG_PAL{ dword back, shad1, contour, left,  right, middle, mwhite; }
  121.          pal = { 0xF0F2F3,0xABB0B2, dgrey,   white, white, dgrey,  white  };
  122.  
  123. void DrawMouseImage(dword l,r,m,v) {
  124.         #define IMG_W 59
  125.         #define IMG_H 100
  126.  
  127.         IF (l) pal.left = red;
  128.         IF (m) pal.middle = red;
  129.         IF (r) pal.right = red;
  130.         IF (v) pal.middle = yellow;
  131.  
  132.         PutPaletteImage(#panels_img_data,IMG_W,IMG_H,18+30,18+16,8,#pal);
  133.         pal.left = pal.right = white;
  134.         pal.middle = dgrey;
  135.         IF (v) {
  136.                 pause(10);
  137.                 DrawMouseImage(l,r,m,0);
  138.         }
  139. }
  140.  
  141. void DrawControls() {
  142.         incn y;
  143.         y.n = FRAME_Y+115;
  144.         pointer_speed.draw(FRAME_X, y.inc(30));
  145.         acceleration.draw(FRAME_X, y.inc(30));
  146.         double_click_delay.draw(FRAME_X, y.inc(30));
  147.         emulation.draw(FRAME_X, y.inc(33));
  148.         madmouse.draw(FRAME_X, y.inc(27));
  149.         com_mouse.draw(FRAME_X, y.inc(27));
  150. }
  151.  
  152. void LoadCfg() {
  153.         acceleration.value = @GetMouseAcceleration();
  154.         pointer_speed.value = @GetMouseSpeed();
  155.         double_click_delay.value = @GetMouseDoubleClickDelay();
  156.         com_mouse.checked = ini_drivers.GetInt("com_mouse", 0);
  157.         madmouse.checked = CheckProcessExists("MADMOUSE");
  158.         emulation.checked = CheckProcessExists("MOUSEMUL");
  159. }
  160.  
  161. void ExitApp() {
  162.         ini_drivers.SetInt("com_mouse", com_mouse.checked);
  163.         ini_mouse.SetInt("speed", pointer_speed.value);
  164.         ini_mouse.SetInt("acceleration", acceleration.value);
  165.         ini_mouse.SetInt("double_click_delay", double_click_delay.value);
  166.         @ExitProcess();
  167. }
  168.  
  169. void ApplyCfg() {
  170.         @SetMouseSpeed(pointer_speed.value);
  171.         @SetMouseAcceleration(acceleration.value);
  172.         @SetMouseDoubleClickDelay(double_click_delay.value);
  173. }
  174.  
  175. void EventClickComMouse()
  176. {
  177.         if (!com_mouse.checked)
  178.         {
  179.                 if (RunProgram("/sys/loaddrv", "COMMOUSE")>=0) {
  180.                         notify(COMMOUSE_LOADED);
  181.                         com_mouse.click(com_mouse.id);
  182.                 } else {
  183.                         notify("'Error running LOADDRV' -E");
  184.                 }
  185.         } else {
  186.                 notify(COMMOUSE_CAN_NOT_UNLOAD);
  187.         }
  188. }
  189.  
  190. stop:
  191.