Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #define MEMSIZE 0x23E80
  3. #include "..\lib\kolibri.h"
  4. #include "..\lib\strings.h"
  5. #include "..\lib\mem.h"
  6. #include "..\lib\file_system.h"
  7. #include "..\lib\dll.h"
  8. #include "..\lib\figures.h"
  9.  
  10. #include "..\lib\lib.obj\libio_lib.h"
  11. #include "..\lib\lib.obj\libimg_lib.h"
  12. #include "..\lib\lib.obj\libini.h"
  13. #include "..\lib\lib.obj\box_lib.h"
  14.  
  15. #include "..\lib\patterns\libimg_load_skin.h"
  16.  
  17. #define WINDOW_TITLE "System panels configuration v0.8"
  18.  
  19. frame taskbar_frame = { 0, 100, 10, 152, 14, 0x000111, 0xFFFfff, 1, " Taskbar ", 0, 0, 6, 0x000111, 0xCCCccc };
  20. frame docky_frame = { 0, 100, 10, 98, 183, 0x000111, 0xFFFfff, 1, " Docky ", 0, 0, 6, 0x000111, 0xCCCccc };
  21.  
  22. char taskbar_ini_path[] = "/sys/settings/taskbar.ini";
  23. char taskbar_category[] = "Flags";
  24. char docky_ini_path[] = "/sys/settings/docky.ini";
  25.  
  26.  
  27. system_colors sc;
  28. proc_info Form;
  29. mouse m;
  30. libimg_image panels_image;
  31.  
  32. struct docky_cfg {
  33.         word fsize;
  34.         byte location, ashow;
  35. } docky_cfg;
  36.  
  37. struct taskbar_cfg {
  38.         byte Attachment;
  39.         byte PanelHeigh;
  40.         byte SoftenUp, SoftenDown, MinLeftButton, MinRightButton, MenuButton,
  41.              RunApplButton, ClnDeskButton, Clock, CpuUsage, ChangeLang;
  42. } taskbar_cfg;
  43.  
  44.  
  45.  
  46. void main()
  47. {
  48.         dword id, key;
  49.  
  50.         mem_Init();
  51.         if (load_dll2(libio,  #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
  52.         if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
  53.         if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini");
  54.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Eror: library doesn't exists - boxlib");
  55.  
  56.         Libimg_LoadImage(#panels_image, abspath("panels_cfg.png"));
  57.  
  58.         LoadCfg();
  59.  
  60.         loop() switch(WaitEvent())
  61.         {
  62.                 case evButton:
  63.                                 id=GetButtonID();
  64.                                 if (id==1) ExitProcess();
  65.                                 //taskbar buttons
  66.                                 if (id>=100) && (id<200)
  67.                                 {
  68.                                         if (id==100) taskbar_cfg.Attachment ^= 1;
  69.                                         if (id==105) taskbar_cfg.SoftenUp ^= 1;
  70.                                         if (id==106) taskbar_cfg.SoftenDown ^= 1;
  71.                                         if (id==107) taskbar_cfg.MinLeftButton ^= 1;
  72.                                         if (id==108) taskbar_cfg.MinRightButton ^= 1;
  73.                                         if (id==109) taskbar_cfg.RunApplButton ^= 1;
  74.                                         if (id==110) taskbar_cfg.ClnDeskButton ^= 1;
  75.                                         if (id==111) taskbar_cfg.Clock ^= 1;
  76.                                         if (id==112) taskbar_cfg.CpuUsage ^= 1;
  77.                                         if (id==113) taskbar_cfg.ChangeLang ^= 1;
  78.                                         if (id==114) taskbar_cfg.MenuButton ^= 1;
  79.                                         DrawWindowContent();
  80.                                         SaveCfg();
  81.                                         RestartProcess("@taskbar");
  82.                                 }
  83.                                 //docky buttons                
  84.                                 if (id>=200)
  85.                                 {
  86.                                         if (id==200)
  87.                                         {
  88.                                                      if (docky_cfg.location==1) docky_cfg.location = 2;
  89.                                                 else if (docky_cfg.location==2) docky_cfg.location = 3;
  90.                                                 else if (docky_cfg.location==3) docky_cfg.location = 1;
  91.                                         }
  92.                                         if (id==201) docky_cfg.fsize ^= 1;
  93.                                         if (id==202) docky_cfg.ashow ^= 1;
  94.                                         DrawWindowContent();
  95.                                         SaveCfg();
  96.                                         RestartProcess("@docky");
  97.                                 }
  98.                                 break;
  99.                                
  100.                 case evKey:
  101.                                 key = GetKey();
  102.                                 if (key==27) ExitProcess();
  103.                                 break;
  104.                        
  105.                 case evReDraw:
  106.                                 sc.get();
  107.                                 DefineAndDrawWindow(130, 150, 400, 300+GetSkinHeight(),0x34,sc.work,WINDOW_TITLE);
  108.                                 GetProcessInfo(#Form, SelfInfo);
  109.                                 if (Form.status_window>2) break;
  110.                                 taskbar_frame.size_x = docky_frame.size_x = - taskbar_frame.start_x * 2 + Form.cwidth;
  111.                                 taskbar_frame.font_color = docky_frame.font_color = sc.work_text;
  112.                                 taskbar_frame.font_backgr_color = docky_frame.font_backgr_color = sc.work;
  113.                                 DrawWindowContent();
  114.         }
  115. }
  116.  
  117.  
  118. void DrawWindowContent()
  119. {
  120.         word win_center_x;
  121.  
  122.   frame_draw stdcall (#taskbar_frame);
  123.         DefineButton(22, taskbar_frame.start_y + 12, panels_image.w-1, 27-1, 100 + BT_HIDE, 0);
  124.         img_draw stdcall(panels_image.image, 22, taskbar_frame.start_y + 12, panels_image.w, 27, 0, taskbar_cfg.Attachment * 27);
  125.         WriteText(68, taskbar_frame.start_y + 20, 0x80, 0x333222, "Click on image to change position");
  126.         PanelCfgCheckBox(22, taskbar_frame.start_y +  48, 105, "Soften Up", taskbar_cfg.SoftenUp);
  127.         PanelCfgCheckBox(22, taskbar_frame.start_y +  68, 106, "Soften Down", taskbar_cfg.SoftenDown);
  128.         PanelCfgCheckBox(22, taskbar_frame.start_y +  88, 107, "Min Left Button", taskbar_cfg.MinLeftButton);
  129.         PanelCfgCheckBox(22, taskbar_frame.start_y + 108, 108, "Min Right Button", taskbar_cfg.MinRightButton);
  130.         PanelCfgCheckBox(22, taskbar_frame.start_y + 128, 109, "Run Application Button", taskbar_cfg.RunApplButton);
  131.         win_center_x = Form.cwidth * 55 / 100;
  132.         PanelCfgCheckBox(win_center_x, taskbar_frame.start_y +  48, 110, "ClnDeskButton - wtf?", taskbar_cfg.ClnDeskButton);
  133.         PanelCfgCheckBox(win_center_x, taskbar_frame.start_y +  68, 111, "Clock", taskbar_cfg.Clock);
  134.         PanelCfgCheckBox(win_center_x, taskbar_frame.start_y +  88, 112, "Cpu Usage", taskbar_cfg.CpuUsage);
  135.         PanelCfgCheckBox(win_center_x, taskbar_frame.start_y + 108, 113, "Change Language", taskbar_cfg.ChangeLang);
  136.         PanelCfgCheckBox(win_center_x, taskbar_frame.start_y + 128, 114, "Menu Button", taskbar_cfg.MenuButton);       
  137.         //PanelCfgCheckBox(22, taskbar_frame.start_y + 64, 204, "111", taskbar_cfg.PanelHeigh);
  138.  
  139.   frame_draw stdcall (#docky_frame);
  140.         DefineButton(22, docky_frame.start_y + 12, panels_image.w-1, 27-1, 200 + BT_HIDE, 0);
  141.         img_draw stdcall(panels_image.image, 22, docky_frame.start_y + 12, panels_image.w, 27, 0, docky_cfg.location * 27 + 27);
  142.         WriteText(68, docky_frame.start_y + 20, 0x80, 0x333222, "Click on image to change position");
  143.  
  144.         PanelCfgCheckBox(22, docky_frame.start_y + 48, 201, "Full width",  docky_cfg.fsize);
  145.         PanelCfgCheckBox(22, docky_frame.start_y + 70, 202, "Always show", docky_cfg.ashow);
  146. }
  147.  
  148. void LoadCfg()
  149. {
  150.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "Attachment", 1);     taskbar_cfg.Attachment = EAX;
  151.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "PanelHeigh", 18);    taskbar_cfg.PanelHeigh = EAX;
  152.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "SoftenUp", 1);       taskbar_cfg.SoftenUp = EAX;
  153.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "SoftenDown", 1);     taskbar_cfg.SoftenDown = EAX;
  154.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "MinLeftButton", 1);  taskbar_cfg.MinLeftButton = EAX;
  155.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "MinRightButton", 1); taskbar_cfg.MinRightButton = EAX;
  156.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "RunApplButton", 1);  taskbar_cfg.RunApplButton = EAX;
  157.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "ClnDeskButton", 1);  taskbar_cfg.ClnDeskButton = EAX;
  158.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "Clock", 1);          taskbar_cfg.Clock = EAX;
  159.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "CpuUsage", 1);       taskbar_cfg.CpuUsage = EAX;
  160.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "ChangeLang", 1);     taskbar_cfg.ChangeLang = EAX;
  161.         ini_get_int stdcall (#taskbar_ini_path, #taskbar_category, "MenuButton", 1);     taskbar_cfg.MenuButton = EAX;
  162.  
  163.         ini_get_int stdcall (#docky_ini_path, "@", "location", 0);  docky_cfg.location = EAX;
  164.         ini_get_int stdcall (#docky_ini_path, "@", "fsize", 0);     docky_cfg.fsize = EAX;
  165.         ini_get_int stdcall (#docky_ini_path, "@", "ashow", 0);     docky_cfg.ashow = EAX;
  166. }
  167.  
  168. void SaveCfg()
  169. {
  170.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "Attachment", taskbar_cfg.Attachment);
  171.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "PanelHeigh", taskbar_cfg.PanelHeigh);
  172.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "SoftenUp", taskbar_cfg.SoftenUp);
  173.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "SoftenDown", taskbar_cfg.SoftenDown);
  174.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "MinLeftButton", taskbar_cfg.MinLeftButton);
  175.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "MinRightButton", taskbar_cfg.MinRightButton);
  176.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "RunApplButton", taskbar_cfg.RunApplButton);
  177.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "ClnDeskButton", taskbar_cfg.ClnDeskButton);
  178.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "Clock", taskbar_cfg.Clock);
  179.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "CpuUsage", taskbar_cfg.CpuUsage);
  180.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "ChangeLang", taskbar_cfg.ChangeLang);
  181.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "MenuButton", taskbar_cfg.MenuButton);
  182.  
  183.         ini_set_int stdcall (#taskbar_ini_path, #taskbar_category, "Attachment", taskbar_cfg.Attachment);
  184.         ini_set_int stdcall (#docky_ini_path, "@", "location", docky_cfg.location);
  185.         ini_set_int stdcall (#docky_ini_path, "@", "fsize", docky_cfg.fsize);
  186.         ini_set_int stdcall (#docky_ini_path, "@", "ashow", docky_cfg.ashow);
  187. }
  188.  
  189. void RestartProcess(dword proc_name)
  190. {
  191.         int i, slot;
  192.         proc_info Process;
  193.         for (i=0; i<1000; i++;)
  194.         {
  195.                 GetProcessInfo(#Process, i);
  196.                 if (strcmpi(#Process.name, proc_name)==0) { KillProcess(Process.ID); break; }
  197.         }
  198.         RunProgram(proc_name, "");
  199.  
  200.         pause(20);
  201.         GetProcessInfo(#Form, SelfInfo);
  202.         slot = GetProcessSlot(Form.ID);
  203.         ActivateWindow(slot);
  204. }
  205.  
  206. void PanelCfgCheckBox(dword x, y, id, text, byte value) {
  207.         CheckBox(x, y, 14, 14, id, text, sc.work_graph, sc.work_text, value);
  208. }
  209.  
  210. stop: