Subversion Repositories Kolibri OS

Rev

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