idle
This commit is contained in:
JianjunLiu 2022-11-24 14:14:16 +08:00
parent af29344e72
commit efe547e628
4 changed files with 103 additions and 94 deletions

View File

@ -40,7 +40,7 @@ type TVclDesignerStart = class(TVclDesigner) //ʵ
_wapi.bringWindowToTop(self.Handle); _wapi.bringWindowToTop(self.Handle);
end end
inherited; inherited;
end end
function CreateParams(p);override; function CreateParams(p);override;
begin begin
inherited; inherited;

View File

@ -215,10 +215,10 @@ type tapplication=class(tcomponent)
**} **}
initialize(); initialize();
{$ifdef linuxgtk} {$ifdef linuxgtk}
idledata :=(new tcbytearray(4))._getptr_(); //idledata :=(new tcbytearray(4))._getptr_();
id := tsl_gtk_idle_interface(idledata);//_wapi.tsl_gtk_idle_interface(idledata); //¹¹Ôìidle //id := tsl_gtk_idle_interface(idledata);//_wapi.tsl_gtk_idle_interface(idledata); //¹¹Ôìidle
_wapi.gtk_main(); _wapi.gtk_main();
_Wapi.g_idle_remove_by_data(idledata); //ɾ³ýidle //_Wapi.g_idle_remove_by_data(idledata); //ɾ³ýidle
return 1; return 1;
{$endif} {$endif}
if not FMessageObj then FMessageObj := new TTagMSG(); if not FMessageObj then FMessageObj := new TTagMSG();

View File

@ -6625,112 +6625,111 @@ function g_main_context_new():pointer;cdecl;external "libgtk-3.so";
function g_main_context_ref(m:pointer):pointer;cdecl;external "libgtk-3.so"; function g_main_context_ref(m:pointer):pointer;cdecl;external "libgtk-3.so";
function g_main_context_acquire(m:pointer):integer;cdecl;external "libgtk-3.so"; function g_main_context_acquire(m:pointer):integer;cdecl;external "libgtk-3.so";
procedure g_main_context_release(m:pointer);cdecl;external "libgtk-3.so"; procedure g_main_context_release(m:pointer);cdecl;external "libgtk-3.so";
type tGtkMessageQueue = class //ÏûÏ¢¶ÓÁÐ type tGtkMessageQueue=class //ÏûÏ¢¶ÓÁÐ
{** {**
@ignore(忽略) @ignore(忽略)
gtk消息队列 gtk消息队列
**} **}
private public
function Create();
public begin
function Create(); Clean();
begin FMainContext := g_main_context_new();
Clean(); g_main_context_ref(FMainContext);
FMainContext := g_main_context_new(); fLock := 0;
g_main_context_ref(FMainContext); end
fLock := 0; function Add(h,m,l,w,obj);
end begin
function Add(h,m,l,w,obj); lock();
begin FData[FLen]:= array(h,m,l,w,obj);
lock(); if FCurrent=FLen then
FLen++; begin
FData[FLen] := array(h,m,l,w,obj); createidle();
unlock(); end
end FLen++;
unlock();
function Feach(); end
begin function Feach();
lock(); begin
if FCurrent<FLen then lock();
begin if FCurrent<FLen then
FCurrent++; begin
r := FData[FCurrent]; r := FData[FCurrent];
if (FCurrent+1<FLen) and FCurrent>100 then FCurrent++;
begin if(FCurrent<FLen)and FCurrent>100 then
FData := FData[FCurrent+1:];//min(FLen-1,FCurrent+100)]; begin
FCurrent := -1; FData := FData[FCurrent:]; //min(FLen-1,FCurrent+100)];
FLen := length(FData); FCurrent :=0;
end FLen := length(FData);
end end
else end else
begin begin
Clean(); Clean();
end end
unlock(); unlock();
return r; return r;
end end
function cleaneasyLostMessage(h,m); function cleaneasyLostMessage(h,m);
begin begin
idx := FCurrent; idx := FCurrent;
lock(); lock();
while idx<FLen do while idx<FLen do
begin begin
idx++; if FData[idx][0]=h and FData[idx][0]=m then
if FData[idx][0]=h and FData[idx][0]=m then begin
begin FData[idx][0]:= 0;
FData[idx][0] := 0; end
end idx++;
end end
unlock(); unlock();
end end
function haseasyLostMessage(h,m); function haseasyLostMessage(h,m);
begin begin
idx := FCurrent; idx := FCurrent;
if idx<FLen then if idx<FLen then
begin begin
idx++; if((h=-1)or(FData[idx][0]=h))and FData[idx][0]=m then
if ((h=-1) or (FData[idx][0]=h)) and FData[idx][0]=m then begin
begin return 1;
return 1; end
end idx++;
end end
end end
private private
function Clean(); function Clean();
begin begin
FData := array();
FData := array(); FLen := 0;
FLen := 0; FCurrent :=0;
FCurrent := -1; end
FData;
end FCurrent;
FData; FLen;
FCurrent; FLock;
FLen; FMainContext;
FLock ;
FMainContext;
function lock() function lock()
begin begin
return ; return;
fLock++; fLock++;
if (fLock=1 )then if(fLock=1)then
begin begin
g_main_context_acquire(FMainContext); g_main_context_acquire(FMainContext);
end end
end end
function unlock() function unlock()
begin begin
return ; return;
if (fLock>0) then if(fLock>0)then
begin begin
fLock--; fLock--;
if (fLock=0) then if(fLock=0)then
begin begin
g_main_context_release(FMainContext); g_main_context_release(FMainContext);
end end
end end
end end
end end
function _gtkeventcall_();//消息回调 function _gtkeventcall_();//消息回调
begin begin
r := class(tgtk_ctl_object).DispatchGtkEventCall(params); r := class(tgtk_ctl_object).DispatchGtkEventCall(params);
@ -6839,6 +6838,11 @@ begin
_wapi.cairo_destroy(cr); _wapi.cairo_destroy(cr);
_wapi.gtk_object_set_data(cr); _wapi.gtk_object_set_data(cr);
end end
function createidle();
begin
idledata :=(new tcbytearray(4))._getptr_();
id := tsl_gtk_idle_interface(idledata);
end
function _gtkidledo_(); //回调 function _gtkidledo_(); //回调
begin begin
d := FeachMessageFromGtkMessageQueue(); d := FeachMessageFromGtkMessageQueue();
@ -6873,19 +6877,22 @@ begin
return 1; return 1;
end end
return r; return 1; //r
end end
else else
begin begin
tslprocessmessages(false); tslprocessmessages(false);
//sleep(10); //sleep(10);
end end
r := 1;
end else end else
begin begin
r := 0;
tslprocessmessages(false); tslprocessmessages(false);
//sleep(10);//休息一下 //sleep(10);//休息一下
end end
unit(uvclthreadworker).RunThreadWorkerHost(); unit(uvclthreadworker).RunThreadWorkerHost();
return r;
end end
procedure tslprocessmessages()begin end; procedure tslprocessmessages()begin end;
function InitGtkWindowClass(); //初始化窗口类 function InitGtkWindowClass(); //初始化窗口类

View File

@ -5566,7 +5566,8 @@ type TcustomStatusBar=class(TCustomControl)
if nv<>FItemOder then if nv<>FItemOder then
begin begin
FItemOder := nv; FItemOder := nv;
InvalidateRect(nil,false); if FItems then
InvalidateRect(nil,false);
end end
end end
function paintb();//从左到右 function paintb();//从左到右
@ -6769,6 +6770,7 @@ end
initialization initialization
{$ifdef linux} {$ifdef linux}
class(tUIglobalData).uisetdata("G_T_TTIMER_",class(TCustomTimer)); class(tUIglobalData).uisetdata("G_T_TTIMER_",class(TCustomTimer));
class(TCustomTimer)._wapi.SetTimer(nil,10000,100,getwinprocptr(2));
{$endif} {$endif}
end. end.